Use Stax to parse XML

Source: Internet
Author: User

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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.