Parses the input stream into a yaidom Document
.
Parses the input stream into a yaidom Document
. Closes the input stream afterwards.
Parses the content of the given File into a eu.cdevreeze.yaidom.simple.Document.
Parses the content of the given File into a eu.cdevreeze.yaidom.simple.Document.
Parses the content of the given URI into a eu.cdevreeze.yaidom.simple.Document.
Parses the content of the given URI into a eu.cdevreeze.yaidom.simple.Document.
DOM-based
Document
parser.Typical non-trivial creation is as follows, assuming class
MyEntityResolver
, which extendsEntityResolver
, and classMyErrorHandler
, which extendsErrorHandler
:If we want the
DocumentBuilderFactory
to be a validating one, using an XML Schema, we could obtain theDocumentBuilderFactory
as follows:A custom
EntityResolver
could be used to retrieve DTDs locally, or even to suppress DTD resolution. The latter can be coded as follows (see http://stuartsierra.com/2008/05/08/stop-your-java-sax-parser-from-downloading-dtds), risking some loss of information:For completeness, a custom
ErrorHandler
class that simply prints parse exceptions to standard output:If more flexibility is needed in configuring the
DocumentParser
than offered by this class, consider writing a wrapperDocumentParser
which wraps aDocumentParserUsingDom
, but adapts theparse
method. This would make it possible to adapt the conversion from a DOMDocument
to yaidomDocument
, for example.A
DocumentParserUsingDom
instance can be re-used multiple times, from the same thread. If theDocumentBuilderFactory
is thread-safe, it can even be re-used from multiple threads. Typically aDocumentBuilderFactory
cannot be trusted to be thread-safe, however. In a web application, one (safe) way to deal with that is to use oneDocumentBuilderFactory
instance per request.