First, we use books. xml under SRC.
<?xml version="1.0" encoding="UTF-8"?><bookstore><book category="COOKING" aaaaaa="111111"><title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author><year>2005</year><price>30.00</price></book><book category="CHILDREN"><title lang="en">Harry Potter</title><author>J K. Rowling</author><year>2005</year><price>29.99</price></book><book category="WEB"><title lang="en">XQuery Kick Start</title><author>James McGovern</author><author>Per Bothner</author><author>Kurt Cagle</author><author>James Linn</author><author>Vaidyanathan Nagarajan</author><year>2003</year><price>49.99</price></book><book category="WEB"><title lang="en">Learning XML</title><author>Erik T. Ray</author><year>2003</year><price>39.95</price></book></bookstore>
The usage of Stax is as follows:
Package COM. jadyer. stax; import Java. io. inputstream; import javax. XML. parsers. documentbuilder; import javax. XML. parsers. documentbuilderfactory; import javax. XML. stream. eventfilter; import javax. XML. stream. factoryconfigurationerror; import javax. XML. stream. xmleventreader; import javax. XML. stream. xmlinputfactory; import javax. XML. stream. xmloutputfactory; import javax. XML. stream. xmlstreamconstants; import javax. XML. stream. xmlstreamexception; import javax. XML. stream. xmlstreamreader; import javax. XML. stream. xmlstreamwriter; import javax. XML. stream. events. xmlevent; import javax. XML. transform. outputkeys; import javax. XML. transform. transformer; import javax. XML. transform. transformerfactory; import javax. XML. transform. transformerfactoryconfigurationerror; import javax. XML. transform. dom. domsource; import javax. XML. tran Sform. stream. streamresult; import javax. XML. XPath. XPath; import javax. XML. XPath. xpathconstants; import javax. XML. XPath. xpathfactory; import Org. w3C. dom. document; import Org. w3C. dom. element; import Org. w3C. dom. nodelist;/*** use Stax to parse XML * @ see Stax (streaming API for XML) * @ create Mar 17,201 3 5:30:31 * @ author Xuan Yu