| |||||
XML Programming NotesIndex
General informationHere is a collection of pointers to relevant standards and tutorials on the Web:
Writing and validating XMLYou can use your favorite editor to edit XML documents. The file name should have suffix .xml. Emacs has a descent SGML mode for editing XML, which is automatically invoked for file names with .xml suffix. There are also many specialized XML editors available, and some of them come with nice templates and automatic validation. Just search for "XML editor" in Google. Some XML and DTD examples can be found on rack40 in /home/dbcourse/examples/xml-zthes/. To check that your XML document is well-formed (i.e., no synatx errors), use the command xmlchecker file on rack40, where file is the file name of the XML document. Note that you will need to set up your environment beforehand (see Getting Started for details). To validate your XML document against a DTD (you will need a <!DOCTYPE declaration in the XML document), use the command xmlchecker -v file. The additional -v flag turns on DTD validation. If you edit XML on a Windows machine, you can fire up Internet Explorer and use it to open your XML document. IE will automatically validate the XML document and display it in a nice format. Using XPath, XQuery, and XSLT with SaxonSaxon is an open-source XPath/XQuery/XSLT engine. To run an XQuery, use your favorite text editor to create a text file, say xqueryFile, containing the query string, and then issue the command saxonxq xqueryFile. The result will be printed to standard output. As an example, you may try a file containing the following XQuery string: <result> { for $i in doc("/home/dbcourse/examples/xml-xmark/auction.xml")//item where $i/payment = "Creditcard" return $i/name } </result> To run an XSLT stylesheet, use the command saxonxsl xmlFile xsltFile, where xmlFile specifies the name of the input XML file, and xsltFile specifies the name of the XSLT stylesheet file. The result will be output to standard output. Coding with JAXPPlenty of examples can be found in /home/dbcourse/examples/jaxp/ on rack40. SaxEcho.java uses an SAX parser to parse and validate an input XML document, and uses SAX API to echo the input to stdout. DomEcho.java uses a DOM parser to parse and validate an input XML document and to build an in-memory DOM representation of the input; it then uses DOM API to print the DOM tree out as XML. DomTree.java prints out the DOM tree representation directly, which can be useful in debugging. The standard way of converting DOM into XML for output is to use a default Transformer, which is illustrated in Stylizer.java. Stylizer.java also shows how to use Transformer to perform XSLT transformations. On rack40, your CLASSPATH is already set up to include the standard JDK library (and hence the JAXP library). Therefore, you can simply use javac *.java to compile your code. However, since the standard CLASSPATH does not include the current directory, you may need to use java -classpath . JavaClassName in the directory containing JavaClassName.class. |
|||||
Last updated Thu Sep 29 09:18:17 EDT 2005 |