我试图呼叫一个Web服务,但面临一个奇怪的行为.我们的服务器上运行了一个Web服务,但代码不对我们开放,因此无法看到墙后面发生了什么服务的所有者已经暴露了基于Web的测试客户端UI,它在文本框中输入并将显示对测试目的的响应.此输入框以下面提到的格式输入
<CONTENT>
<CONTENTID></CONTENTID>
<DOCUMENTID>DRI2</DOCUMENTID>
<LOCALECODE>en_US</LOCALECODE>
<LATEST_VERSION>false</LATEST_VERSION>
<INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT>
<ACTIVITY_TYPE></ACTIVITY_TYPE>
</CONTENT>
Run Code Online (Sandbox Code Playgroud)
它在这个用户界面上工作得很好,但是当我试图通过我的java代码调用这个Web服务时它连接以及获得服务授权但是当我试图调用上面的方法它给我以下错误消息
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException: Content is not allowed in prolog.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(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.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206) …Run Code Online (Sandbox Code Playgroud) 我正在验证Java中的XMLSchema,并且当我有无效的内容模型时会抛出SAXParseExceptions.
我将使用这些异常来突出验证失败的位置 - 但SAXParseExceptions似乎有点过低.
例如,对于枚举失败,我得到的有效性错误是所提供的值与一个例外中的内容模型不匹配,以及它在下一个例子中应用的元素.
我想我需要一个实用程序抽象一点将相关的错误合并在一起,并将异常文本解析为可用的异常属性.
这是一种合理的方法,还是我只是缺少某些东西,或者是图书馆或助手班?
更新@timgilbert,感谢您的回复.
例如,我在t'internet上找到了一个SAXParseException
cvc-pattern-valid: Value 'en' is not facet-valid
with respect to pattern '([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*'
Run Code Online (Sandbox Code Playgroud)
对我来说关键的事情是
我希望能够做的一个例子就是让人们提交一份文件,并通过用户友好的消息突出显示验证失败的文件 - 上面的错误消息似乎不太友好......必须解析单引号就像是一场等待发生的事故:)
我想我可能做错了"引用元素"的事情,也许我应该默认将文档的身份转换作为验证的一部分,并使用验证错误属性来扩充转换可以用CSS挑选出来.如果我需要解析消息以使它们更友好,那仍然无济于事......
Re:紧密绑定,javax.xml.validation.Validator.validate()抛出org.xml.sax.SAXException无论如何 - 不知道如何摆脱假设绑定...
干杯
在尝试解析android上的xml文档时,我收到"SAXParseException:意外的文档结束"错误.
有问题的文件来自google weather api,但无论有问题的xml文件(只要xml有效),似乎都会抛出相同的错误,所以我怀疑这是我的方法的问题,而不是xml.
这是作为一个学习练习,所以我可能(希望)忽略了一些明显的东西=)
我通过在线验证器运行xml,然后它恢复正常.(不能告诉我它是否有效,因为我没有DTD,但我认为我不需要DTD来解析xml).
这是我用来尝试解析文件的代码:
private void refreshForecast()
URL url;
try {
url = new URL( "http://192.168.1.66:8000/google4.xml");
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection)connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// falls over here parsing the xml.
Document dom = db.parse(in);
}
} catch (ManyExceptions e) {
....
}
Run Code Online (Sandbox Code Playgroud)
产生错误的xml的缩减版本是:
<?xml version="1.0"?>
<xml_api_reply version="1">
<weather>
<forecast_information>
<city>Hamilton</city>
</forecast_information>
</weather>
</xml_api_reply>
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪是:
11-20 …Run Code Online (Sandbox Code Playgroud) I have been attempting to resolve this final issue with validating the return xml from the api to the xsd, in almost all instances that are similar the solution is to add the following line: elementFormDefault="qualified" however this line is already included in both the originating xsd and the child xsd.
The submitted xml is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SignedConfig>
<Config>
<RequestID>9cb5b8fe-62d8-4d52-ba32-58f1d1cc5909</RequestID>
<ClientID>1234</ClientID>
<ClientIP>172.1.1.0</ClientIP>
<HelpURI>http://www.google.com/HELP_URI</HelpURI>
<BravaServerURL>http://www.google.com/BRAVA_SERVER_URL</BravaServerURL>
<UserName>Kenneth Test</UserName>
<MaxCacheSize>1</MaxCacheSize>
<NumberPreloadedPages>2</NumberPreloadedPages>
<UseMultiPartPost>false</UseMultiPartPost>
<ResolveDBTokensURI>http://www.google.com/RESOLVE_DBTOKENS_URI</ResolveDBTokensURI>
<UI>
<UiOverride>UI Variant</UiOverride>
<CssOverride>CSS Theme</CssOverride>
<SinglePageLayout>true</SinglePageLayout>
<EnableRasterRenderer>true</EnableRasterRenderer>
<Hide>
<Widget>closeButton</Widget> …Run Code Online (Sandbox Code Playgroud) 此代码用于从其String表示生成XML文档.它在我的小单元测试中工作正常,但在我的实际xml数据中失败了.它触发的行是Document doc = db.parse(is);
有任何想法吗?
public static Document FromString(String xml)
{
// from http://www.rgagnon.com/javadetails/java-0573.html
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document doc = db.parse(is);
doc.normalize();
return doc;
}
catch (Exception e)
{
Log.WriteError("Failed to parse XML", e, "XML.FromString(String)");
return null;
}
}
Run Code Online (Sandbox Code Playgroud) 我处于这样一个位置:我使用Java连接到TCP端口,并且一个接一个地流式传输XML文档,每个文档都以<?xml文档标记的开头分隔.演示格式的示例:
<?xml version="1.0"?>
<person>
<name>Fred Bloggs</name>
</person>
<?xml version="1.0"?>
<person>
<name>Peter Jones</name>
</person>
Run Code Online (Sandbox Code Playgroud)
我正在使用org.xml.sax.*api.SAX解析适用于第一个文档,但在遇到第二个文档的开头时抛出异常:
Exception in thread "main" org.xml.sax.SAXParseException: The processing instruction
target matching "[xX][mM][lL]" is not allowed.
Run Code Online (Sandbox Code Playgroud)
以下框架类演示了我正在使用的设置:
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import java.io.FileReader;
public class XMLTest extends DefaultHandler {
public XMLTest() {
super();
}
public static void main(String[] args) throws Exception {
XMLReader xr = XMLReaderFactory.createXMLReader();
XMLTest handler = new XMLTest();
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
xr.parse(new InputSource(new Socket("127.0.0.1", 4555).getInputStream()));
}
}
Run Code Online (Sandbox Code Playgroud)
我有过XML(这是一个财务数据饲料)的格式无法控制,但我需要能够有效地分析它,并解析所有的文件.我花了整个下午/晚上尝试不同的事情,但没有一个产生结果.任何帮助将不胜感激.
我有一个主报告,有4个子报告.在iReport(版本4.1.3)中生成报告时,报告生成成功.但是,当报告部署在JBoss服务器中时,会出现以下错误
Error Parsing Styled Text
"org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference jasper reports".
Run Code Online (Sandbox Code Playgroud)
它的相应空白报告没有与datsource进行任何映射即可成功生成.但是从数据源获取值的那个抛出了这个错误.
你能告诉我可能是什么问题吗?
iReport版本:4.1.3
数据源:XML数据源
如果您需要更多信息,请与我们联系.
使用 dom4j DOMDocument 来提供 validator.validate(DOMSource) 在 java 1.6 中失败(xsi:noNamespaceSchemaLocation 不允许出现在根元素中),在 1.5 中有效
我发现以下问题非常棘手(好吧,这是轻描淡写) - 任何见解将不胜感激。目前似乎最好的主意是放弃 dom4j 以支持 XOM(http://stackoverflow.com/questions/831865/what-java-xml-library-do-you-recommend-to-replace-dom4j)。
我一直在验证从 dom4j 'new DOMDocument()' 创建的内存 XML - 但这不适用于 Java 6。
以下对 dom4j (1.6.1) DOMDocument 派生的 DOMSource 的 validate(source) 调用适用于 Java 1.5.x,但在 Java 1.6.x 中失败:
public void validate() throws Exception {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(null);
Schema schemaXSD = schemaFactory.newSchema(new URL(getSchemaURLString()));
Validator validator = schemaXSD.newValidator();
DOMSource source = new DOMSource(getDocument());
validator.validate(source);
}
Run Code Online (Sandbox Code Playgroud)
getSchemaURLString() 也用于在根节点添加 xsi:noNamespaceSchemaLocation 属性,即: xsi:noNamespaceSchemaLocation="http://localhost:8080/integration/xsd/fqlResponseSchema-2.0.xsd"
异常如下:
Exception: org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' …Run Code Online (Sandbox Code Playgroud) 关于 Android 上使用 Java 的 Sax XML 解析器的问题:我需要解析从 Web 获取的 XML 文件,但我无法控制该文件。有些包含错误并导致解析器因“标签不匹配”或“格式不正确(无效标记)”等错误而中止。
这些错误对我来说并不重要,我想忽略它们并继续前进,我可以处理损坏的 XML 结构。但我无法修复 XML 文件,它们不是我的。我如何告诉 Android 上的 Sax(类 org.xml.sax.XMLReader)不要抛出异常并继续运行?附加 ErrorHandler 不起作用,捕获异常也没有用,因为我无法在停止的地方继续解析。
我的 XML 不是 HTML,但这里有一些 (X)HTML 示例,浏览器会忽略错误并继续运行。我也想做这个。
我不想编写自己的解析器来处理字符集转换等。我不需要验证 XML。这是我的代码,精简为要点:
XMLReader r = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
r.setErrorHandler(new MyLenientErrorHandlerThatNeverThrows());
r.setContentHandler(new MyImporterThatExtendsDefaultHandler());
r.parse(new InputSource(new BufferedReader(...)));
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试在 Tomcat 上部署 JAX-WS Web 服务。我正在 Eclipse 中生成战争。我在运行 Tomcat 时遇到的错误是 -
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem:
Failed to import bean definitions from relative location [ws/ws-context.xml]
Offending resource: ServletContext resource [/WEB-INF/spring/application-context.xml];
nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: ...
nested exception is org.xml.sax.SAXParseException:
src-resolve: Cannot resolve the name 'cxf-beans:beanAttributes' to a(n) 'attribute group'
component.
Run Code Online (Sandbox Code Playgroud)
有问题的 xml 文件是
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context …Run Code Online (Sandbox Code Playgroud)