StAX 似乎没有将其识别为处理指令。它发现这些事件: - StartEvent - EndEvent "?> - CharacterEve-6ren">
gpt4 book ai didi

java - Stax处理指令

转载 作者:行者123 更新时间:2023-11-30 05:13:15 24 4
gpt4 key购买 nike

我正在尝试使用 StAX 解析这样的处理指令:

<?item something="<some_element></some_element>"?>

StAX 似乎没有将其识别为处理指令。它发现这些事件:

< - CharacterEvent
?item something=" - CharacterEvent
<some_element> - StartEvent
</some_element> - EndEvent
"?> - CharacterEvent

整个事件不应该被视为单个ProcessingInstruction事件吗?

最佳答案

按我的预期工作。这段代码:

String xml = "<?item something=\"<some_element></some_element>\"?><foo></foo>";
XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(new StringReader(xml));
while (reader.hasNext()) {
final XMLEvent event = reader.nextEvent();
System.out.println(event + " - " + event.getClass().getSimpleName());
}

打印此内容:

<?xml version="1.0" encoding='null' standalone='no'?> - StartDocumentEvent
<?itemsomething="<some_element></some_element>"?> - ProcessingInstructionEvent
<foo> - StartElementEvent
</foo> - EndElementEvent
ENDDOCUMENT - EndDocumentEvent

这是 Java 6。您使用的是哪个 Java 版本?

关于java - Stax处理指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2593730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com