Detailed explanation of xml parsing examples by javaDOMParser

Source: Internet
Author: User
Code snippets, code sharing, PHP code sharing, Java code sharing, Ruby code sharing, Python code sharing, HTML code sharing, CSS code sharing, SQL code sharing, and JavaScript code sharing
Import java. io. *; import java.net. *; import org. w3c. dom. *; import org. w3c. dom. node. *; import oracle. xml. parser. v2. *;/*** ----------------------------------------------------------------------------------- * Demonstrate how to use DOM. ** @ version 1.0 * @ author Jeffrey M. hunter (jhunter@idevelopment.info) * @ author http://www.idevelopment.info * Optional */public class DOMExample {/** + --------------------------------------------- + * | METHOD: main | * + signature + */static public void main (String [] argv) {try {if (argv. length! = 1) {// must pass in the name of the XML file System. err. println ("Usage: java DOMExample filename"); System. exit (1);} // Get an instance of the parser DOMParser parser = new DOMParser (); // Generate a URL from the filename URL url = createURL (argv [0]); // Set varous parser options; validation on, // warnings shown, error stream set to stderr. parser. setErrorStream (System. err); parser. setValidationMode (true); parser. showWarnings (true); // parse the document parser. parse (url); // Obtain the document XMLDocument doc = parser. getDocument (); // print document elements System. out. print ("The elements are:"); printElements (doc); // print document elements attributes System. out. println ("The attributes of each element are:"); printElementAttributes (doc);} catch (Exception e) {System. out. println (e. toString () ;}/ ** + ------------------------------------------------- + * | METHOD: printElements | * + principal + */static void printElements (Document doc) {NodeList nodelist = doc. getElementsByTagName ("*"); Node node; for (int I = 0; I
 
  

The above is the detailed description of the java DOMParser xml parsing instance. 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.