在我的办公室里,仅仅提到Xerces这个词就足以煽动开发者的凶悍愤怒.粗略地看一眼其他Xerces关于SO的问题似乎表明,几乎所有Maven用户都会在某个时候"触及"这个问题.不幸的是,理解这个问题需要对Xerces的历史有一点了解......
Xerces是Java生态系统中使用最广泛的XML解析器.几乎每个用Java编写的库或框架都以某种身份使用Xerces(传递,如果不是直接的话).
包含在官方二进制文件中的Xerces罐子直到今天还没有版本化.例如,Xerces 2.11.0实现jar是命名的xercesImpl.jar
而不是xercesImpl-2.11.0.jar
.
Xerces团队不使用Maven,这意味着他们不会将正式版本上传到Maven Central.
Xerces曾经作为单个jar(xerces.jar
)发布,但被分成两个jar,一个包含API(xml-apis.jar
),另一个包含这些API的实现(xercesImpl.jar
).许多较旧的Maven POM仍然声明依赖xerces.jar
.在过去的某个时刻,Xerces也被释放xmlParserAPIs.jar
,一些较老的POM也依赖于它.
分配给xml-apis和xercesImpl的版本由那些将其jar部署到Maven存储库的人通常是不同的.例如,xml-apis可能是1.3.03版本,而xercesImpl可能是2.8.0版本,即使两者都来自Xerces 2.8.0.这是因为人们经常使用它实现的规范版本来标记xml-apis jar.还有就是这是一个非常不错的,但不完全击穿这里.
更复杂的是,Xerces是包含在JRE中的Java API for XML Processing(JAXP)的参考实现中使用的XML解析器.实现类在com.sun.*
命名空间下重新打包,这使得直接访问它们很危险,因为它们可能在某些JRE中不可用.但是,并非所有Xerces功能都通过API java.*
和javax.*
API 公开; 例如,没有API公开Xerces序列化.
几乎所有的servlet容器(JBoss,Jetty,Glassfish,Tomcat等)都会在一个或多个/lib
文件夹中附带Xerces .
对于上述某些原因(或许是全部原因),许多组织在其POM中发布和使用Xerces的自定义构建.如果你有一个小应用程序并且只使用Maven Central,这不是一个真正的问题,但它很快成为企业软件的问题,其中Artifactory或Nexus代理多个存储库(JBoss,Hibernate等):
例如,组织A可能发布xml-apis
为:
<groupId>org.apache.xerces</groupId>
<artifactId>xml-apis</artifactId>
<version>2.9.1</version>
Run Code Online (Sandbox Code Playgroud)
同时,组织B可能会发布jar
如下:
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
Run Code Online (Sandbox Code Playgroud)
虽然B的jar
版本低于A版jar
,但Maven并不知道它们是同一个版本,因为它们有不同
groupId
的版本.因此,它无法执行冲突解决,并且两个
jar
s都将作为已解析的依赖项包含在内:
我正在尝试针对许多不同的模式验证XML文件(为人为的例子道歉):
c.xsd特别是导入b.xsd和b.xsd导入a.xsd,使用:
<xs:include schemaLocation="b.xsd"/>
我试图通过Xerces以下列方式执行此操作:
XMLSchemaFactory xmlSchemaFactory = new XMLSchemaFactory();
Schema schema = xmlSchemaFactory.newSchema(new StreamSource[] { new StreamSource(this.getClass().getResourceAsStream("a.xsd"), "a.xsd"),
new StreamSource(this.getClass().getResourceAsStream("b.xsd"), "b.xsd"),
new StreamSource(this.getClass().getResourceAsStream("c.xsd"), "c.xsd")});
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlContent)));
Run Code Online (Sandbox Code Playgroud)
但这无法正确导入所有三个模式,导致无法将名称'blah'解析为(n)'组'组件.
我已经使用Python成功验证了这一点,但是在Java 6.0和Xerces 2.8.1中存在实际问题.任何人都可以在这里建议出现问题,或者更简单的方法来验证我的XML文档?
我正在使用JSF 2.0,NetBeans 6.9.1,GlassFish Server 3.1,mojarra 2.0.3和JasperReports 3.7.6开发Web应用程序.我的项目库中包含jar文件"xerces-2.8.0.jar".此文件作为JasperReports jar文件库的一部分导入.每当我尝试通过NetBeans部署,运行或调试我的项目时,都会收到以下错误:
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory.
Run Code Online (Sandbox Code Playgroud)
在我的项目中的任何更改后,我的构建失败,当我尝试部署,运行或调试它时,我收到上述错误.我必须重新启动服务器并再次运行/调试.我搜索过互联网,无法找到解决这个问题的方法.我查看了有问题的jar文件,并且DTDDVFactoryImpl确实从DTDDVFactory扩展 - 我不知道为什么我收到此错误.虽然我最终可以让我的项目运行,但如果我没有收到此错误会更好.
任何人都可以告诉我如何解决这个问题?我是否需要从项目库中删除此文件?我是否需要使用较新版本/旧版本更新此文件?
我正在使用Java 6.我在我的pom中有这种依赖...
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.10.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此行解析XHTML文档
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>JA</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]-->
Run Code Online (Sandbox Code Playgroud)
使用此代码...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setExpandEntityReferences(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final DocumentBuilder builder = factory.newDocumentBuilder();
final InputSource s …
Run Code Online (Sandbox Code Playgroud) 我正在尝试进行模式验证,目前使用的是javax.xml.validation.SchemaFactory
.不幸的是,当我调用该newSchema(Source schema)
函数时,我收到以下错误:
Caused by: org.xml.sax.SAXParseException; systemId: file:/C:/Users/C42056/Documents/workspace-sts-3.2.0.RELEASE/cec-sample-ws-integration-2-war/target/classes/WEB-INF/schemas/xsd/individual/PrivateComponentTypes_4_0.xsd; lineNumber: 33; columnNumber: 88; src-resolve: Cannot resolve the name 'utility:ObjectStatusDateType' to a(n) 'type definition' component.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at com.sei.ec.xml.validation.SimpleXmlValidator.loadSchema(SimpleXmlValidator.java:70)
at com.sei.ec.xml.validation.SimpleXmlValidator.<init>(SimpleXmlValidator.java:83)
... 75 more
Run Code Online (Sandbox Code Playgroud)
该utility:ObjectStatusDateType
元素用于我传递给newSchema(Source schema) …
我想vcpkg
在 Windows 的 CMake 项目中使用,因为我需要boost
并且xerces
都由这个包管理器处理。
我有以下几点CMakeLists.txt
:
cmake_minimum_required (VERSION 3.12.0)
project (myproj)
set (CMAKE_PREFIX_PATH ${XERCES_ROOT})
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
unset (Boost_INCLUDE_DIR CACHE)
unset (Boost_LIBRARY_DIRS CACHE)
# set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules)
find_package (Boost COMPONENTS filesystem regex REQUIRED)
find_package (XercesC CONFIG REQUIRED)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
message (STATUS "binary dir is ${CMAKE_BINARY_DIR}")
include_directories (${CMAKE_BINARY_DIR}/${PROJECT_NAME}/)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories (${Boost_INCLUDE_DIRS})
include_directories (${XercesC_INCLUDE_DIRS})
set (PROJECT_SRC
code.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
add_dependencies (${PROJECT_NAME} UPDATE_RESOURCES)
target_link_libraries (${PROJECT_NAME} ${Boost_LIBRARIES} XercesC::XercesC) …
Run Code Online (Sandbox Code Playgroud) 如何在解析文档时强制SAX解析器(特别是Java中的Xerces)在输入文档中没有任何 doctype的情况下使用DTD ?这甚至可能吗?
以下是我的方案的更多细节:
我们有一堆XML文档符合由多个不同系统生成的相同DTD(我无法更改).其中一些系统会在其输出文档中添加doctype,而其他系统则不会.有些使用命名字符实体,有些则不使用.有些使用命名字符实体而不声明doctype. 我知道这不是犹太人,但这是我必须要合作的.
我正在研究需要用Java解析这些文件的系统.目前,它通过首先将XML文档作为流读取,尝试检测是否已定义doctype,并添加doctype声明(如果尚未存在)来处理上述情况.问题是这个代码是错误的,我想用更干净的东西替换它.
文件很大,所以我不能使用基于DOM的解决方案.我也在尝试解析字符实体,因此使用XML Schema 没有帮助.
如果您有解决方案,请直接发布而不是链接到它?如果将来有一个带有死链接的正确解决方案,它不会做很好的Stack Overflow.
我确信我不是第一个遇到这种冲突的人.
我继承的代码执行以下操作:
org.w3c.dom.Document dom; // declaration
javax.xml.validation.Schema schema; // declaration
...
...
...
javax.xml.validation.Validator validator = schema.newValidator();
validator.validate(new DOMSource(dom));
Run Code Online (Sandbox Code Playgroud)
其中...
代表看似不重要/无关代码
使用JDK 6编译和运行代码可以工作(并且始终有......)
最近,我不得不将我公司其他地方编写的另一个组件集成到我的代码中.该组件绝对需要包含在类路径中xercesImpl-2.8.1.jar
我绝对需要这个第三方组件,但现在运行上面的代码不再有效,我得到以下内容:
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Root'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Validator.java:127)
Run Code Online (Sandbox Code Playgroud)
作为一个解决方案,我想也许以某种方式在自己的类加载器中屏蔽xercesImpl-2.8.1.jar,但是没有设法这样做,可能是因为缺乏类加载器知识或者可能是因为它不是要走的路.关于我的环境的另一件事,我的应用程序运行在tomcat 5.5和6 ...
顺便说一下调试时我注意到我跑的时候 dom.getImplementation()
xercesImpl-2.8.1.jar …
大家好我正在尝试使用Java中的Neko/Xerces解析DOM树.
NodeList divs = this.doc.getElementsByTagName("DIV");
for(int i=0; i < divs.getLength(); i++) {
NodeList images = divs.item(i).parentNode().getElementsByTagName("IMG");
// operate on these
}
Run Code Online (Sandbox Code Playgroud)
是我理想的喜欢做的事情.看来我只能调用getElementsByTagName
文件本身?难道我做错了什么?我应该能够在一个Node
元素上调用它吗?
我可以从文档中看到它不存在:http://xerces.apache.org/xerces-j/apiDocs/org/w3c/dom/Node.html所以也许我需要以另一种方式做到这一点?
谢谢!
我正在尝试运行Apache Hadoop 1.21,但是我遇到了这个异常:
Failed to set setXIncludeAware(true) for parser org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@2662e5cf:java.lang.UnsupportedOperationException
Run Code Online (Sandbox Code Playgroud)
完整堆栈跟踪:
13/10/17 17:22:52 ERROR conf.Configuration: Failed to set setXIncludeAware(true) for parser org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@2662e5cf:java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation or earlier: class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation or earlier: class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
at javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(DocumentBuilderFactory.java:589)
at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:1131)
at org.apache.hadoop.conf.Configuration.loadResources(Configuration.java:1107)
at org.apache.hadoop.conf.Configuration.getProps(Configuration.java:1053)
at org.apache.hadoop.conf.Configuration.get(Configuration.java:460)
at org.apache.hadoop.fs.FileSystem.getDefaultUri(FileSystem.java:132)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:124)
at main.JobExecutor.executeModelCreation(JobExecutor.java:223)
at main.JobExecutor.main(JobExecutor.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.hadoop.util.RunJar.main(RunJar.java:160)
Run Code Online (Sandbox Code Playgroud)
我已经找了近3天的解决方案,我找到了几个网站(比如这个:Hadoop"无法为解析器设置setXIncludeAware(true)"错误以及如何解决它),建议将xerces和xalan添加到maven依赖.还有其他网站,建议几乎相反 …