我正在使用此链接使用DOM生成XML文件.它说"Xerces解析器与JDK 1.5发行版捆绑在一起.所以你不需要单独下载解析器."
但是,当我在Eclipse Helios中编写以下行时,即使我的系统中有Java 1.6,它也会产生编译时错误.
import org.apache.xml.serialize.XMLSerializer;
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我已经通过Maven安装了Xerces:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
然后,我在Xerces FAQ中尝试了此示例中给出的代码,以针对1.1版中的模式验证XML文件.这是我的代码:
private static void validateFile(File xmlFile, File xsdFile) throws SAXException, IOException
{
// 1. Lookup a factory for the W3C XML Schema language
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1");
// 2. Compile the schema.
File schemaLocation = xsdFile;
Schema schema = factory.newSchema(schemaLocation);
// 3. Get a validator from the schema.
Validator validator = schema.newValidator();
// 4. Parse the document you …Run Code Online (Sandbox Code Playgroud) 我使用Eclipse 创建了一个GWT项目,该项目运行良好(我能够在托管模式和Google App Engine上运行),直到我尝试导入Google Web Toolkit的Gears API.将以下行添加到我的java源文件后:
import com.google.gwt.gears.client.geolocation.Geolocation;
Run Code Online (Sandbox Code Playgroud)
我尝试编译时收到以下错误:
19-Jun-2009 3:36:09 AM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: failed com.google.apphosting.utils.jetty.DevAppEngineWebAppContext@1c7d682{/,C:\Documents and Settings\Geoff Denning\workspace\TaskPath\war}
javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found
Run Code Online (Sandbox Code Playgroud)
我已经将gwt-gears.jar文件添加到我的\ war\WEB-INF\lib目录中,我在Eclipse中引用它如下:
Eclipse中的Java构建路径http://i41.tinypic.com/148klk4.png
我甚至打开了gwt-gears.jar文件并确认org/apache/xerces/jaxp/SAXParserFactoryImpl.class确实存在.任何人都可以给我任何指示,为什么我得到上述错误?
我支持使用Xerces-C进行XML解析的遗留C++应用程序.我被.Net宠坏了,并习惯使用XPath从DOM树中选择节点.
有没有办法在Xerces-C中访问一些有限的XPath功能?我正在寻找像selectNodes("/ for/bar/baz")之类的东西.我可以手动执行此操作,但相比之下XPath非常好.
我的应用程序希望它有时会尝试解析无效的XML文档.我目前抓住了"SAXParseException:prolog中不允许内容." 例外,工作正常.但是,Xerces仍然觉得需要将自己的消息打印到控制台:
[Fatal Error] :1:1: Content is not allowed in prolog.
Run Code Online (Sandbox Code Playgroud)
有没有办法禁用它?
当我尝试导入org.apache.xml.serialize.XMLSerializer时,我得到以下错误消息:
The import org.apache.xml.serialize.XMLSerializer cannot be resolved
Run Code Online (Sandbox Code Playgroud)
谁能告诉我原因?谢谢!!
我有一个依赖于HTTP BUilder的项目,这给了我后续的依赖树:
[INFO] +- org.codehaus.groovy.modules.http-builder:http-builder:jar:0.5.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.3.2:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | +- net.sf.json-lib:json-lib:jar:jdk15:2.3:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | +- commons-lang:commons-lang:jar:2.4:compile
[INFO] | | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] | +- net.sourceforge.nekohtml:nekohtml:jar:1.9.9:compile
[INFO] | | \- xerces:xercesImpl:jar:2.8.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] | \- xml-resolver:xml-resolver:jar:1.2:compile
Run Code Online (Sandbox Code Playgroud)
在我添加hibernate-entitymanager后,xml-apis:aml-apis更改版本.突然,Maven更喜欢使用版本1.0b2,这是dom4j的传递依赖:
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.1.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | +- org.hibernate:hibernate-core:jar:4.3.1.Final:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] …Run Code Online (Sandbox Code Playgroud) 我正在Eclipse中开发一个GWT应用程序并使用jdom2来读取一些自定义的xml属性文件.
在最近的更新之后,我的应用程序现在在尝试读取xml文件时失败并出现上述错误.相关的堆栈跟踪是:
org.apache.xerces.parsers.XIncludeAwareParserConfiguration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
org.apache.xerces.parsers.SAXParser.<init>(Unknown Source)
org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.<init>(Unknown Source)
org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source)
org.jdom2.input.sax.XMLReaders.createXMLReader(XMLReaders.java:165)
org.jdom2.input.SAXBuilder.createParser(SAXBuilder.java:871)
org.jdom2.input.SAXBuilder.buildEngine(SAXBuilder.java:854)
org.jdom2.input.SAXBuilder.getEngine(SAXBuilder.java:904)
org.jdom2.input.SAXBuilder.build(SAXBuilder.java:1116)
uk.co.platosys.db.jdbc.DatabaseProperties.loadProperties(DatabaseProperties.java:78)
Run Code Online (Sandbox Code Playgroud)
研究此问题表明,当类路径上存在不兼容的xerces jar版本时,可能会出现错误.
gwt-dev-2.6.1.jar包含xerces包,我的预感是这个最新版本的gwt-dev捆绑了一个不兼容的版本.然而,当前版本的jdom2.0.5与2.11版本的Xerces一起发布,这似乎是Apache最新发布的版本.将这些罐子放在我的类路径上似乎无法解决问题; 我以前能够依赖gwt-dev中的版本.
我宁愿在这方面做到这一点,而且远远超出了我的舒适区.
我正在努力让声纳为一个包含Findbugs规则的质量档案的项目工作.
然而,在分析项目时,声纳反任务会因以下错误而崩溃:
Caused by: java.io.IOException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
at edu.umd.cs.findbugs.filter.Filter.<init>(Filter.java:134)
at edu.umd.cs.findbugs.FindBugs.configureFilter(FindBugs.java:516)
at edu.umd.cs.findbugs.FindBugs2.addFilter(FindBugs2.java:374)
at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.java:136)
... 50 more
Run Code Online (Sandbox Code Playgroud)
在这个项目中,依赖关系是用ivy解决的,并且不依赖于像xerces和xalan这样的库.另外我明白xerces包含在JVM中并且总是很乐意处理......
我试图添加各种依赖项用于sonar.libraries属性,但没有效果添加本地JRE库也似乎没有太大的影响.
如何运行这个findbugs分析(以独立于机器的方式)?
(声纳版本:4.4,findbugs3插件)
更新:我刚刚发现冲突的来源是在构建中早期有一个目标,删除它修复它.当然我非常想保留我的常春藤报告,所以问题仍然是我如何让这个工作......?
我正在尝试设计一个模式来验证已经在应用程序中使用的xml格式(重新设计xml的空间不大).
我正在尝试利用xml架构字典的key和keyref元素来验证身份约束.
一个特别的问题是xml模拟一对多关系的方式
<spaceships>
<spaceship guns="gun1 gun2 gun3"/>
</spaceships>
<guns>
<gun id="gun1"/>
<gun id="gun2"/>
<gun id="gun3"/>
</guns>
Run Code Online (Sandbox Code Playgroud)
我在我的架构中想出了这对key/keyref
<xs:key name="gunKey">
<xs:selector xpath="guns/gun" />
<xs:field xpath="@id" />
</xs:key>
<xs:keyref name="gunRef" refer="gunKey">
<xs:selector xpath="spaceships/spaceship" />
<xs:field xpath="@guns" />
</xs:keyref>
Run Code Online (Sandbox Code Playgroud)
这不会与xerces抗议验证:
键'gun1 gun2 gun3'键'gunRef'找不到元素的身份约束.
无论如何,在模式中表示列表的值是逗号分隔的对另一个实体的引用列表,并仍然获得身份约束验证的好处?