开发者

Stax processing instruction

开发者 https://www.devze.com 2022-12-25 18:38 出处:网络
I\'m trying to parse a processing instruction like this using StAX: <?item something=\"<some_element></some_element>\"?>

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=" - CharacterE开发者_JS百科vent
<some_element> - StartEvent
</some_element> - EndEvent
"?> - CharacterEvent

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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号