Sample code for simple parsing of XML using SAX

Source: Internet
Author: User
This article describes sample code sharing for simple parsing of XML by using SAX. if you need it, refer Sample code for simple parsing of XML using SAX

Package com. zkn. xmlparse. text; import java. io. file; import java. util. iterator; import org. dom4j. attribute; import org. dom4j. document; import org. dom4j. element; import org. dom4j. io. SAXReader ;/***

Title:

**

Description:

** @ Since: 12:40:10 **/public class XMLParseTest02 {public static void main (String [] args) throws Exception {SAXReader reader = new SAXReader (); document document = reader. read (new File ("src/mapping. xml "); Element element = document. getRootElement (); getElement (element);} public static void getElement (Element element) {/*** get the tag name */String elements = element. getName (); Iterator Ite = element. attributes (). iterator (); String attrName = ""; while (ite. hasNext () {Attribute attr = (Attribute) ite. next (); attrName + = attr. getName () + "=" + attr. getValue () + "";} System. out. println ("element name:" + elements + "attribute:" + attrName); Iterator It = element. elements (). iterator (); while (it. hasNext () {Element ele = (Element) it. next (); // recursively call getElement (ele );}}}

The above is the details shared by the sample code for simple parsing of XML by SAX. For more information, see other related articles in the first PHP community!

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.