The system is looking for the order of the XML parser

xiaoxiao2021-03-06  61

With the development of XML technology, there are more and more XML parsers, such as Xerces, Crimson, Lark, etc. Some parsers are supported by Schema and DTD validations, and some are not supported.

So, when there is a plurality of parsers in the system, how do this program choose a parser?

For example, you quote the JAR package of others, and it is very likely that different JAR packages use different parsers to cause conflicts.

By reading the JDK source Javax.xml.Parsers.FactoryFinder, javax.xml.parsers.saxParserFactory and DocumentBuilderFactory found JDK as follows:

1. System properties javax.xml.Parsers.DocumentBuilderFactory or javax.xml.parsers.saxparserfactory

2. Javax.xml.Parsers.DocumentBuilderFactory or javax.xml.parsers.SaxParserFactory property set in JDK-DIR / LIB / JAXP.PROPERTIES

3. The value set in Meta-INF / Services / Javax.xml.ParsRS.DocumentBuilderFactory or javax.xml.parsers.SaxParserFactory files during the running jar package

4. If the parser above is not found, crimson is used. If not yet. . . . . . That can only ClassNotFound.

To look for an XML parser.

In this way, we can set the corresponding XML parser by calling System.SetProperty ("Javax.xml.Pars.DocumentBuilderFactory," org.apache.crimson.jaxp.documentbuilderfactoryImpl "), or generates a jaxp.properties file, where Join the following

Javax.xml.Parsers.DocumentBuilderFactory = org.apache.crimson.jaxp.documentbuilderFactoryImpl

Or add the file name Javax.xml.Parsrs.DocumentBuilderFactory when playing a jar package, then write org.apache.crimson.jaxp.documentBuilderFactoryImpl

转载请注明原文地址:https://www.9cbs.com/read-84881.html

New Post(0)