<?xml version="1.0" encoding="UTF-8"?>
<mes:SubmitStructureRequest xmlns:mes="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:str="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure" xmlns:reg="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/registry" xmlns:web="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/webservices">
<mes:Header>
<mes:ID>TEST_DFD</mes:ID>
<mes:Test>true</mes:Test>
<mes:Prepared>2013-10-10</mes:Prepared>
<mes:Sender id="TESTER"/>
<mes:Receiver id="ESTAT"/>
</mes:Header>
<mes:SubmitStructureRequest action="Append">
<str:Structures>
<str:Dataflows>
<str:Dataflow agencyID="ESTAT" id="DFD_TEST_21" version="1.0">
<com:Name xml:lang="en">Production in construction, total, building construction, civil engineering (Monthly)</com:Name>
<str:Structure>
<Ref agencyID="ESTAT" class="DataStructure" id="STS" package="datastructure" version="2.0"/>
</str:Structure>
</str:Dataflow>
</str:Dataflows>
</str:Structures>
</mes:SubmitStructureRequest>
</mes:SubmitStructureRequest>
我正在尝试使用这段Java代码来解析它(流是前面提到的xml):
InputStream stream = sourceData.getInputStream();
try {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader parser = factory.createXMLStreamReader(stream);
while (parser.hasNext()) {
int event = parser.next();
if (event == XMLStreamConstants.START_ELEMENT) {
for(int i = 0 ; i < parser.getNamespaceCount(); i ++) {
String ns = parser.getNamespaceURI(i);
if(SdmxConstants.getNamespacesV1().contains(ns)) {
return SDMX_SCHEMA.VERSION_ONE;
}
if(SdmxConstants.getNamespacesV2().contains(ns)) {
return SDMX_SCHEMA.VERSION_TWO;
}
if(SdmxConstants.getNamespacesV2_1().contains(ns)) {
return SDMX_SCHEMA.VERSION_TWO_POINT_ONE;
}
}
throw new SdmxSyntaxException("Can not get Scheme Version from SDMX message. Unable to determine structure type from Namespaces- please ensure this is a valid SDMX document");
}
}
throw new SdmxSyntaxException(ExceptionCode.XML_PARSE_EXCEPTION, "No root node found");
} catch(XMLStreamException e) {
throw new SdmxSyntaxException(ExceptionCode.XML_PARSE_EXCEPTION, e);
} finally {
if(stream != null) {
try {
stream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
在int事件= parser.next();我得到:
com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
任何想法为什么会这样?
解决方法:
证据表明您实际上已经尝试解析空流.
它说在尝试解析序言时发现了EOF.您向我们展示的XML中的序言没有错,尤其是解析器遇到EOF时没有任何合理的理由.因此,我推断您显示给我们的XML不是解析器实际看到的.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。