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?
精彩评论