我的应用程序组成了一个来自多个xml源的网页模型.使用普通的Xerces解析器将这些源解析为内存为DOM对象.不幸的是,Xerces DOM对象对于只读操作不是线程安全的.我希望能够重用已解析的DOM进行读取.有没有人知道我使用的另一个解析器或一个简单的线程安全的读取DOM实现?
当xercesImpl.jar作为库包含时,我无法在NetBeans Web应用程序中创建Web服务客户端.
使用NetBeans 6.9和GlassFish 3.0.1:
1.)创建新的Web应用程序
2.)创建新的Web服务
3.)向创建的Web服务添加新操作(只需让它返回null - 实现并不重要)
4.)将Web服务部署到GlassFish(工作正常)
5.)添加xercesImpl.jar(我使用的是版本2.9.1)作为Web服务的库(我需要xerces用于我正在使用的第三方库)
6.)停止Glassfish.
7.)清理并构建项目.
8.)运行项目.测试Web服务是否仍然有效(确实如此).
9.)创建一个新的Web服务客户端.将它指向WSDL(我正在使用http://www.webservicex.com/CurrencyConvertor.asmx?wsdl作为测试).
10.)停止Glassfish.
11.)清理并构建项目.
显示错误消息:
C:\ NetBeansProjects\WSTest \nbproject\jaxws-build.xml:43:启动wsimport时出错:BUILD FAILED(总时间:1秒)
第43行是:
<wsimport sourcedestdir="${build.generated.dir}/jax-wsCache/CurrencyConvertor"
destdir="${build.generated.dir}/jax-wsCache/CurrencyConvertor" wsdl=
"${basedir}/${conf-dir}xml-resources/web-service-references/
CurrencyConvertor/wsdl/www.webservicex.com/CurrencyConvertor.asmx.wsdl"
catalog="catalog.xml" extension="true" verbose="true"
wsdlLocation="http://www.webservicex.com/CurrencyConvertor.asmx?wsdl"
xnocompile="true" xendorsed="true">
Run Code Online (Sandbox Code Playgroud)
12.)重新启动NetBeans.
13.)清理并构建项目.(构建现在可以工作)
14.)运行项目.除了这个单行错误消息外,GlassFish启动正常:
严重:解析目录时出错
15.)加载Web Service Tester页面会在GlassFish日志中产生以下异常:
WARNING: Servlet web service endpoint 'NewWebService' failure
java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [META-INF/services/org.apache.xerces.xni.parser.XMLParserConfiguration], because it has not yet been started, or was already stopped
at org.glassfish.web.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2085)
at org.glassfish.web.loader.WebappClassLoader.findResource(WebappClassLoader.java:1018)
at org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1255)
at …
Run Code Online (Sandbox Code Playgroud) 我有XML数据,例如:
<feed>
<entry>
<id>4</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title2</title>
</entry>
<entry>
<id>3</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title1</title>
</entry>
<entry>
<id>2</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title1</title>
</entry>
<entry>
<id>1</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title</title>
</entry>
</feed>
Run Code Online (Sandbox Code Playgroud)
我需要结果如下:
<feed>
<entry>
<id>1</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title</title>
</entry>
<entry>
<id>2</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title1</title>
</entry>
<entry>
<id>3</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title1</title>
</entry>
<entry>
<id>4</id>
<updated>2011-01-18T16:55:54Z</updated>
<title>title2</title>
</entry>
</feed>
Run Code Online (Sandbox Code Playgroud)
基本上我需要XSLT对标题进行排序,然后是ID.我已经制作了一个XSLT,但最后出现的时间较短(使用Xerces):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="atom:feed">
<xsl:copy>
<xsl:apply-templates select="*" />
<xsl:for-each select="atom:entry">
<xsl:sort …
Run Code Online (Sandbox Code Playgroud) 当XSL将大量数据转换为HTML时,我经常遇到性能问题.这些数据通常只是几个非常大的表,大致有这种形式:
<table>
<record>
<group>1</group>
<data>abc</abc>
</record>
<record>
<group>1</group>
<data>def</abc>
</record>
<record>
<group>2</group>
<data>ghi</abc>
</record>
</table>
Run Code Online (Sandbox Code Playgroud)
在转换过程中,我希望在视觉上对这些记录进行分组
+--------------+
| Group 1 |
+--------------+
| abc |
| def |
+--------------+
| Group 2 |
+--------------+
| ghi |
+--------------+
Run Code Online (Sandbox Code Playgroud)
这是一个愚蠢的实现(设置来自http://exslt.org.实际的实现有点不同,这只是一个例子):
<xsl:for-each select="set:distinct(/table/record/group)">
<xsl:variable name="group" select="."/>
<!-- This access needs to be made faster : -->
<xsl:for-each select="/table/record[group = $group]">
<!-- Do the table stuff -->
</xsl:for-each>
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)
很容易看出这往往会有O(n^2)
复杂性.更糟糕的是,因为每个记录中都有很多字段.操作的数据可以达到几十MB,记录的数量可以达到5000.在最坏的情况下,每个记录都有自己的组和50个字段.而且为了使事情变得更糟,还有另一层次的分组可能就是这样O(n^3)
现在会有很多选择:
/table/record/group
<xsl:apply-templates/>
在这个用例中,这种 …我正在使用Xerces库来解析XML.以下是用于解析的代码段:
Document doc = builder.parse(new InputSource(new StringReader(someXMLString)));
我需要手动关闭InputStream
in InputSource
还是parse
方法处理它?
我正在尝试编译一些Maven Reversions项目。不幸的是,我得到了错误:
Failed to execute goal org.apache.rat:apache-rat-plugin:0.10:check (check) on project maven: Too many files with unapproved license: 2 See RAT report
Run Code Online (Sandbox Code Playgroud)
由于有人建议跳过检查,所以我正在使用命令
mvn -X -Drat.skip=true compile
mvn -X -Drat.skip=true test-compile
Run Code Online (Sandbox Code Playgroud)
我也试过
-Drat.numUnapprovedLicense=100
-Dlicense.skip=true
-Drat.ignoreErrors=true
Run Code Online (Sandbox Code Playgroud)
使用skip可以进行一些还原,但是即使使用skip,现在仍然出现此错误。
这是堆栈跟踪:
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Apache Maven
[INFO] Maven Model
[INFO] Maven Artifact
[INFO] Maven Plugin API
[INFO] Maven Model Builder
[INFO] Maven Settings
[INFO] Maven Settings Builder
[INFO] Maven Repository …
Run Code Online (Sandbox Code Playgroud) 我们有使用tomcat托管的多个java web应用程序.一些应用程序包括xercesImpl jar,其他应用程序不包括xercesImpl.jar.
为简单起见,假设我们只有两个应用程序:
两个应用程序在引导时都进行一些xml解析,并且仅使用java.*和javax.*(不直接导入org.apache.xerces).
如果xxx.war首先启动,而yyy.war在尝试解析xml时遇到错误,会发生什么:
Caused by: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:230)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:191)
at ca.icod.personne.adressePostale.RecuperateurFormat.createXMLReader(RecuperateurFormat.java:246)
at ca.icod.personne.adressePostale.RecuperateurFormat.parse(RecuperateurFormat.java:214)
... 127 more
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1856)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1705)
at org.xml.sax.helpers.NewInstance.newInstance(NewInstance.java:82)
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:228)
Run Code Online (Sandbox Code Playgroud)
当应用程序以相反的顺序启动时,启动时没有问题.我假设发生的是当xxx.war启动时,找到xercesImpl,因此读取内部的META-INF/services文件夹,因此xerces被标记为要在JVM中使用的xml实现.然后当yyy.war尝试点xml的东西时,JVM仍然认为它应该使用xerces但这次它不在类路径上:ClassNotFoundException
我们希望从我们的应用程序中逐步删除xerces,因为jdk的默认实现似乎可以完成这项工作.
但是我们几乎不能一次性删除xerces,也不能将托管xerces的webcat的tomcat服务器与托管xercesless webapps的托管服务器分开.
我是否想念一些奇怪的事情,或者有人在这里解决了类似问
我正在构建一个使用磁贴的Struts2 Web应用程序但是我发现了一个非常令人沮丧的问题,即如果apache.org关闭(这似乎经常发生)Web应用程序无法启动.这是因为在其标准设置中,StrutsTilesListener尝试加载tiles defenitions文件,该文件包含一个带有public-id的DOCTYPE,该公共id指向位于tiles.apache.org上的DTD.
当应用程序启动时,使用Apache Xerces通过Apache Commons Digester加载定义文件,该文件尝试从tiles.apache.org加载DTD但是如果apache.org关闭则会失败并且随之而来的是整个Web应用程序无法启动.
我可以通过下载文件并将其置于本地并在struts定义文件中指定新的本地位置来绕过远程位置的下载,但是这个解决方案不是很便携,因为本地保存DTD的位置可能会有所不同开发人员机器和不同的一旦上传到实时环境,所以我将不得不继续编辑位置,以便运行webapp运行的机器,这简直是烦人的.
项目中没有其他xml文件存在此问题,包括struts.xml文件,该文件在apache.org上也有DTD位置,所以很明显存在一个设置问题,其中Tiles严格要求DTD但其他组件不是.这有什么解决方案吗?我已经没有耐心了,我不能把这个webapp知道,如果我重新启动apache.org,那么webapp就不会再回来了.
Struts tile defenition文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="master" template="/tiles/templates/master.jsp">
</definition>
<definition name="public" extends="master">
<put-attribute name="header" value="/tiles/templates/public/header.jsp" />
<put-attribute name="footer" value="/tiles/templates/public/footer.jsp" />
<put-attribute name="templateMeta" value="/tiles/templates/public/meta.jsp" />
</definition>
</tiles-definitions>
Run Code Online (Sandbox Code Playgroud)
当apache.org关闭时,堆栈跟踪
SEVERE: Exception sending context initialized event to listener instance of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.IllegalStateException: Unable to instantiate container.
at org.apache.tiles.web.startup.TilesListener.contextInitialized(TilesListener.java:60)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) …
Run Code Online (Sandbox Code Playgroud) 我想在我的 JAXP 和 Xerces2 中使用特定于语言环境的错误消息。默认情况下,只有英文消息可用。
第一步是检索消息文件并将它们放入包“org/apache/xerces/impl/msg/” - 完成。通过使用Locale.setDefault (Locale.GERMANY)
德语消息显示,所以这是有效的。
但我希望在每个实例的基础上对消息进行不同的本地化。所以一个解析器应该返回英语消息,另一个解析器应该返回德语消息。
我用来创建 SAX2 解析器的代码是:
org.xml.sax.XMLReader ret = XMLReaderFactory.createXMLReader ();
Run Code Online (Sandbox Code Playgroud)
对于 DOM,我正在使用 DocumentBuilder 喜欢这个(非常简化):
final DocumentBuilderFactory aDocumentBuilderFactory = DocumentBuilderFactory.newInstance ();
final DocumentBuilder aDocBuilder = aDocBuilderFactory.newDocumentBuilder ();
final Document doc = aDocumentBuilder.parse (aInputSource);
Run Code Online (Sandbox Code Playgroud)
我找到了类似org.apache.xerces.impl.XMLErrorReporter
具有setLocale(Locale)
方法的类的东西,但我没有找到获取/设置它的方法。
顺便说一下,切换到 SAX1 不是一个选项。
任何帮助表示赞赏!
我在这个博客上寻找类似的帖子,但找不到我的问题的答案,所以我决定寻求帮助。
我用 Java 编写了这个简单的函数:
public void open(InputStream stream) throws FoliumFatalException {
try {
InputSource is = new InputSource(stream);
DocumentBuilderFactory dfact = DocumentBuilderFactory.newInstance();
// /* OWASP: inhibit access to External Entities */
dfact.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
dfact.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
_doc = dfact.newDocumentBuilder().parse(is);
} catch (Throwable t) {
_logger.error(t, t);
throw new FoliumFatalException("ENG-0017", "Errore di parsing su stream", t);
}
}
Run Code Online (Sandbox Code Playgroud)
我的目标是应用此处公开的 OWASP 标准,但出现以下错误:
java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source) ~[xercesImpl-2.8.0.jar:?]
at agora.folium.engine.impl.j2ee.FoliumJ2eeXmlParserImpl.open(FoliumJ2eeXmlParserImpl.java:108) [classes/:?] …
Run Code Online (Sandbox Code Playgroud) xerces ×10
java ×8
tomcat ×2
xslt ×2
dtd ×1
eclipse ×1
glassfish ×1
localization ×1
maven ×1
netbeans ×1
performance ×1
struts2 ×1
web-services ×1
xalan ×1
xerces2-j ×1
xml ×1
xml-parsing ×1