Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

xml



The xml package contains additional classes useful for XML parsing.

XML parser

Main Article: XMLSAXParser

The XMLSAXParser class simplifies the creation of XML SAX parser. It works with the ResolverSAXHandler handler.

It allows to either:

The parser can be configured such as exceptions or XML warnings encountered during the validation will not be shown: A custom EntityResolver Can be used for resolving entities during the parsing[1]
As for example the EntityListResolver in the same package
.

ResolverSAXHandler

Main Article: ResolverSAXHandler

The XMLSAXParser class works with the ResolverSAXHandler handler.

Setting the locale

Main Article: Setting the locale

By default, the Locale of the parser is the default locale of the platform. However, it is possible to change the locale of the parser.

Examples

Create a validating parser using a DTD

  XMLSAXParser parser = new XMLSAXParser("My Parser");
  parser.setValidating(true);
  parser.setHandlerDTD(dtd);
  parser.setHandler(handler);
  parse.parse(file);

Create a validating parser using a Schema

  XMLSAXParser parser = new XMLSAXParser("My Parser");
  parser.setValidating(true);
  parser.setSchema(schema);
  parser.setHandler(handler);
  parse.parse(file);

Create a validating parser and get the parsing exceptions

  XMLSAXParser parser = new XMLSAXParser("My Parser");
  parser.setValidating(true);
  parser.setSchema(schema);
  parser.setHandler(handler);
  parser.showExceptions(false);
  parse.parse(file);

  if (handler.hasParserExceptions()) {
    List>ResolverSAXHandler.ExceptionResult> results = handler.getExceptionResults();
  }

EntityListResolver

Main Article: EntityListResolver

The EntityListResolver class manage entity resolution in XML files. It implements all the following interfaces:

This class offer a framework to resolve resources encountered in XML files (including XML Schemas).

Note that this class is able to resolve sibling entities of an entity which has been resolved. For example, if the following systemID is resolved:
  • "http://location/refXSD.xsd" => "D:/myFiles/schemas/refXSD.xsd"
Then upon encountering the following entity (for example referred to in refXSD.xsd):
  • "http://location/childSchema.xsd"
The resolver will look for the following resource:
  • "D:/myFiles/schemas/childSchema.xsd"

XMLWriter

The XMLWriter class is a helper class which allows to write an XML Document.

XMLRootDetector

Main Article: XMLRootDetector

The XMLRootDetector class allows to get the root element of an XML file or only its name. Note that this class uses a Stax parser, which means that it will stop the parsing as soon as this element has been encountered.

The XML root element is a XMLNode, which maintains the structure of the XML content, including the parent-children nodes relationships.

XMLTreeHandler

Main Article: XMLNode and XMLRoot

The XMLTreeHandler class allows to get the tree of XML elements in an XML file. The result will be a XMLNode, which maintains the structure of the XML content, including the parent-children nodes relationships.

XML Includer

Main Article: XML Includer

The XMLIncluder class process the XInclude declarations in a XML file and creates a returning Reader[2]
Note that if you want to parse and validate an XML file, you don't need to use this class directly, but you can directly configure the XML parser class
.

For example:
  XMLIncluder includer = new XMLIncluder(<my XML file>);
  String content = includer.getContent();
The XMLNodeIncluder class does the same but uses the xml.tree nodes to create the tree structure.

For example:
   XMLNodeIncluder includer = new XMLNodeIncluder(<my XML file>);
   includer.write(<my output XML file>);

XMLNodeUtilities


The XMLNodeUtilities class contains various utilities concerning XML content. It work on the XMLNode root of the XML content: The XMLNodeUtilities2 class does the same thing, but has only instance methods. This class offers more customization capabilities.

Notes

  1. ^ As for example the EntityListResolver in the same package
  2. ^ Note that if you want to parse and validate an XML file, you don't need to use this class directly, but you can directly configure the XML parser class

See also


Categories: packages | xml

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences