If the DTD and Schema declared in XML are on the network, the parser may not be able to obtain the Schema during parsing, resulting in parsing failure.
The solution is to use the XML Catalog. The parser requests resources from it, and whether the resources returned by the XML Catalog are in the network or are transparent to the parser locally
1. Sax Parsing
The API for using XML Catalog for Sax Parsing is:
-Org. xml. sax. XMLReader. setEntityResolver ()
-Org. xml. sax. EntityResolver
-Org. xml. sax. ext. EntityResolver2
EntityResolver is used for the Sax 1.0 parser and the EntityResolver2 extension EntityResolver is used for the Sax 2 parser. If the parser is a Sax 2 parser and the EntityResolver2 object is specified, the EntityResolver2 interface method is used. Otherwise, the EntityResolver interface method is used.
2. DOM Parsing
Main APIs:
-Javax. xml. parsers. DocumentBuilder. setEntityResolver ()
-Javax. xml. parsers. DocumentBuilderFactory. setSchema ()
-Javax. xml. validation. Schema
-Javax. xml. validation. SchemaFactory. setResourceResolver ()
-Org. w3c. xml. ls. LSResourceResolver
Not to mention