Java XML applications use local Catalog

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.