Stax处理指令

发布于 2024-08-28 04:33:01 字数 385 浏览 5 评论 0原文

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

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

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

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

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

I'm trying to parse a processing instruction like this using StAX:

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

StAX doesn't appear to recognize this as a processing instruction. It finds these events:

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

Shouldn't the whole thing be considered a single ProcessingInstruction event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2024-09-04 04:33:01

按我的预期工作。此代码:

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 版本是什么?

Works as expected for me. This code:

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());
}

Prints this:

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

That is with Java 6. What Java version are you using?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文