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!