Discover java code to read xml file, include the articles, news, trends, analysis and practical advice about java code to read xml file on alibabacloud.com
Use JS to read XML files, here only consider IE browser
Step1 Create a DOM object
Copy Code code as follows:
function CreateDOM () {
var xmldoc = null;
try {//ie
if (typeof arguments.callee.activeXString!= ' string ') {
var versions = [
"MSXML2. domdocument.6.0 ",
"MSXML2. domdocument.3.0
The example of this article for you to share the Java parsing/reading XML file method for your reference, the specific contents are as follows
XML file
Java Code:
Pa
Web effects p/jsp.html target=_blank >jsp Tutorial Add, delete, read the content code of the specified tag in the XML file
Package XML;
Import Java.io.file;Import java.util.list;
Import org.dom4j.document;Import org.dom4j.documentexception;Import org.dom4j.element;Im
nodesfor (int i = 0; i Get the node for each corresponding position INode Node1 = Childnodes.item (i);if ("Account". Equals (Node1.getnodename ())) {If the name of the node is "account", the Account element property type is outputSystem.out.println ("\ r \ n found an account. Owning area: "+ node1.getattributes (). getNamedItem (" type "). Getnodevalue () +". ");Get the node under NodeList nodedetail = Node1.getchildnodes ();Traverse for (int j = 0; J Get Node detail = Nodedetail.item (j);if ("
1. Use the indexof () and substring () provided by the string class to quickly get specific content in a file
public static void Main (string[] args) {
//test where a word appears
String reqmessage = "
This Java implementation of the use of a simple string class to read the contents of a tag in an XML
Package test.com;Import Java.io.FileInputStream;Import Javax.xml.parsers.DocumentBuilder;Import Javax.xml.parsers.DocumentBuilderFactory;Import org.w3c.dom.Document;Import org.w3c.dom.Element;Import Org.w3c.dom.Node;Import org.w3c.dom.NodeList;public class Xmlparser {public static void Main (string[] args) throws Exception {GetXML ("Src/parameters.xml", "holdername");}/*** @desc Gets the value of the node based on the value of the key property***/public static string GetXML (string Sqlxmlpath, S
Attribute cls = Component.attribute ("class"); System.out.println ("[Class:]" + cls.gettext ()); Iterates through all the properties of the current component for (Iterator ite = Component.elementiterator ("property"); Ite.hasnext ();) {Element property = (Element) Ite.next (); Gets the property's name attribute and the value Attribute pname = Property.attribute ("name"); System.out.println ("[" + pname.gettext () + "]:" + prope
Each project requires a configuration file to extract variable items for program development and maintenance:
You have compiled an xml file reading class and can call the attributes and values of the xml file in the form of strings. In fact, you can directly obtain the attri
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.