开发者

Java SAX: Parsing XML file on the fly

I'm trying to get informations from a XML file in Java with SAX.

I found some examples with a class that implements ContentHandler interface and it work well when I run the parse method on an entire 开发者_开发技巧file well formed with XmlReaderFactory class.

But my goal is to parse an XML file on the fly from stdin for example, I'd like to get XML informations markups by markups like:

> <foo>
markup = foo
> <bar a="baz">
markup = bar
attribute a = baz
> </bar>
end markup bar
> </foo>
end markup foo

But when I pass theses inputs step by step to the parser it stops at the first entry and say

[Fatal Error] :1:10: XML document structures must start and end within the same entity.

Is there a solution to do this. I'm only allowed to use SAX to do this :-( for my school exercise.

Thanks for your help,

Arthur.


your markup is invalid xml. specifically the foo element is ended before the bar element

<foo>
<bar>
</foo>
</bar>

if the markup was correct, you should be able to do what you like.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜