我有这个 XML 文档,它是 SOAP 请求的主体:
<?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 event = parser.next(); 我得到:
com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
知道为什么会这样吗?
最佳答案
证据表明您实际上已尝试解析一个空流。
它说在尝试解析序言时发现了 EOF。您向我们展示的 XML 中的序言没有任何问题,特别是没有合理的理由让解析器遇到 EOF。因此,我推断您向我们展示的 XML 并不是解析器实际看到的内容。
关于java - 解析 XML 时序言中出现意外的 EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108159/
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht