If you get the contents of the tags inside the XML file in the Java class.

Source: Internet
Author: User

Import java.io.IOException;
Import Java.io.InputStream;
Import Java.util.HashMap;
Import Java.util.Map;

Import Javax.xml.parsers.DocumentBuilderFactory;
Import javax.xml.parsers.ParserConfigurationException;

Import org.w3c.dom.Document;
Import org.w3c.dom.Element;
Import org.w3c.dom.NodeList;
Import org.xml.sax.SAXException;

Import Com.sun.javafx.sg.prism.web.NGWebView;

Import Sun.security.x509.KeyIdentifier;


public class GetXML {
Public Document GetDocument () {
Document Doc=null;
The absolute path to the XML file.
InputStream In=thread.currentthread (). Getcontextclassloader (). getResourceAsStream (". xml");
try {
Doc=documentbuilderfactory.newinstance (). Newdocumentbuilder (). Parse (in);
} catch (Saxexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (Parserconfigurationexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return doc;
}
public void GetTags () {
Document doc=this.getdocument ();
Gets the <action> element in the XML file.
NodeList nodelist=doc.getelementsbytagname ("action");
for (int i=0;i<nodelist.getlength (); i++) {
Element element= (Element) Nodelist.item (i);//a specific ACTION element
Gets the property value inside each action element. , you can encapsulate an object into a map key-value pair.
If the <action> tag is nested with other tags, you can go through the for loop.
String Name=element.getattribute ("name");
String Classname=element.getattribute ("class");
String Method=element.getattribute ("method");
}
}
}

If you get the contents of the tags inside the XML file in the Java class.

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.