首页 > 代码库 > About Java XMLEventReader

About Java XMLEventReader

Recently I‘m dealing with a source code data mining project, and I have to use XML in it. But something confusing happens to me. So I searched on Google and finally it got clear.

In this project, I use Event Iterator API of Streaming API for XML (StaX) to parse the XML files. I found a wonderful tutorial here. It really helped me a lot, thanks Lars.

But there is one thing the tutorial missed. Since XMLEventReader works as streaming, it cannot get all data from a event by only reading once. For example, when the content of a node (data between a start element and an end element) contains &lt; or &gt; (tagged by SAX, ‘<‘ and ‘>‘ originally), by calling event.asCharacters().getData(), only characters before these two are fetched. If you want to get them all, a loop should be used here.

<script type="text/javascript" src="https://gist.github.com/zhhailon/5263325.js"></script>

About Java XMLEventReader