|
|
jXML Package |
|
||||||||||||||||
| About News Products Publications People / Contact us Links | ||||||||||||||||||
| Overview Amiga Java - INDEX - Archive - Server - SMTP - SQL - Util - XML - Octopus - TrackTime GNU/Linux |
This software is not fully XML compliant but for situations where name-space support and other advanced capabilities are not required, it is more than sufficient and can reduce significantly the distribution size and memory overhead for applications for which a "full-blown" and completely standards-compliant XML parser would be overkill. This parser's predominant strength lies in its simplicity and light-weight implementation (five classes is all it takes), and its ease-of-use (see below). The software recognizes the "encoding" property in the "<?xml . . . ?>" header, preserves (but does not in any way use a DTD encoded or referenced by) a "<!DOCTYPE . . . >", and parses CDATA sections as well as a mixture of Node and text nodes. In other words, it supports the majority of key-features of XML and cuts out the 10% that would increase the code size and resource requirements many times over. If you are looking for a parser that supports SAX or DOM, on the other hand, this is not the one for you! If you need name space support, schema validation, or anything beyond the basic features, or you wish to engage in full-scale and uncompromising interchange of XML documents, you should probably look at a product like Xerces from the Apache Project. One of the strengths of this parser is its diagnostic ability: a missing (or misspelled) closing element will be pointed out by name and line in the source; missing quotes or other syntactic errors will likewise be reported by line number in the source. Most other parsers report nothing more than "a problem"; our parser actually helps you fix problems! This software is also ideal for structured configuration files, and easy handling of data mostly internal to an application, or where export/import of data does not rely on more than basic XML. Example: Consider the following XML document (let's call it 'test.xml'):
<!xml version="1.0" encoding="UTF-8"?>
<xmlTest>
<Name value="Banal XML Test"/>
<Author>
<Name value="Udo Schuermann"/>
<Email value="nobody@nowhere.net"/>
<Birthday>
<Month value="9" name="September"/>
<DayOfMonth value="3"/>
</Birthday>
</Author>
</xmlTest>
The following code demonstrates retrieval of the 'value' attribute of the <Name> Node:
import com.ringlord.xml.Document;
import com.ringlord.xml.Node;
class TestXML
{
static final public void main( String[] args )
{
Document doc = Document.parse( new File("test.xml") );
Node root = doc.getRootNode();
System.out.println( "This is a '" + root.getName() + "' document" );
Node author = root.getChild( "Author" );
System.out.println( "The author's name is " +
author.getChild("Name").getAttributeValue("value") );
System.out.println( "And all of the author's information is:n" +
author.toString() );
}
}
The output of this program will be:
This is a 'xmlTest' document
The author's name is Udo Schuermann
And all of the author's information is:
<Author>
<Name value="Udo Schuermann"/>
<Email value="nobody@nowhere.net"/>
<Birthday>
<Month value="9" name="September"/>
<DayOfMonth value="3"/>
</Birthday>
</Author>
|
|||||||||||||||||
|
The alteration of any part of this content by manual or automated means (adding, removing, or in any other way altering links, text, or images) constitutes misrepresentation of our content in violation of United States copyright law. For more details, please see our content ownership details page for elaboration. |
||||||||||||||||||