我有一个简单的 Java 程序,如下所示,它读取一个 xml 文件并将其打印在控制台中:
FileInputStream in = new FileInputStream(new File("/tmp/test.xml"));
InputStreamReader streamReader = new InputStreamReader(in);
OMXMLParserWrapper builder = BuilderUtil.getBuilder(streamReader);
SOAPEnvelope envelope = (SOAPEnvelope)builder.getDocumentElement();
//the namespace prefix is OK here (java 7 and java 8)
System.out.println(envelope.getHeader().getChildrenWithLocalName("Ticket").next());
//but after the toString() method, the prefix has modified (java 7 = not change, java 8 = change)
//attribute mustUnderstand and role
System.out.println(envelope.toString());
XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<S:Header>
<abc:Ticket xmlns:abc="somevalue" xmlns:uebernehmeAbschlussdatenXBRL="abcSomevalue" S:mustUnderstand="true" S:role="http://www.w3.org/2003/05/soap-envelope/role/next">
<abc:value>long value</abc:value>
</abc:Ticket>
</S:Header>
<S:Body>
<sample>data</sample>
</S:Body>
</S:Envelope>
当我使用woodstox-core-asl-4.4.1、stax2-api-3.1.4和axiom在 Java 7 中运行程序时,它工作正常。但是当我在 Java 8 中运行相同的东西时, S:role 和 S:mustunderstand 将更改为 env:role 和 env:mustunderstand (S 前缀更改为 env)
如果我从程序中删除woodstox-core-asl-4.4.1和stax2-api-3.1.4,它在 Java 8 中也可以正常工作。
我无法弄清楚这里的问题。这是否意味着woodstox 不支持Java 8 或者我错过了其他东西?