This article mainly introduces the example code for Java to generate and parse XML files and strings. For more information, see section 1. basic knowledge:
Java parses XML in four ways: DOM, SAX, JDOM, and DOM4J.
2. Introduction1) DOM(1) Introduction
The interface provided
Xml
strSourceFile = Server.MapPath (dataxml "/advertisement/" id "/adv.xml")Set objxml =server.createobject ("Microsoft.XMLDOM") ' creates an XML pair likeObjxml.load (strsourcefile) ' reads the XML file into memorySet Xml=objxml.documentelement.selectsinglenode ("advertisem
And if you use XmlReader, you do not need caching, fast reading, but if you want to query is not so convenient, do not support XPath, only through the reader () method forward loop. To avoid the disadvantages of the above two methods, come up with the following scenarios:
1, first use XmlReader to read the contents of the XML file into a linked list.
2, query
Java Xml tutorial (7) Use JDOM to modify XML file content
JDOM provides a flexible way to operate XML files. It is very simple to use JDOM and the code is concise and readable. We have learned how to use JDOM to parse XML files.
The method is not many, can use is good.I'm using dom4j. Dependency> groupId>dom4jgroupId> Artifactid>dom4jArtifactid> version>1.6.1version> Dependency>The contents of the read file are as follows:XML version= "1.0" encoding= "UTF-8"?>Users> ModuleID= "1"> UserIndex= "1"> name>Tomname> Password>12345Password> Date>20150526Date> User>
The XML file format is as follows:Read a property in a nodeXmlDocument doc=new XmlDocument ();Doc. Load ("config +");XmlNode Xnuser=doc. selectSingleNode ("UserData");String Flag=xnuser. attributes["CreateUser"]. InnerText;Reading values from a nodeXmlDocument doc=new XmlDocument ();Doc. Load ("config +");XmlNode xnserver = doc. selectSingleNode ("Userdata/dataconnection/server");Modify the properties of a
1. after open is used to open a file, remember to call the close () method of the file object. For example, you can use the tryfinally statement to ensure that the file can be closed at last. File_objectopen(thefile.txt) try: all_the_textfile_object.read () finally: file_object.close () Note: The open statement cannot
Copy Code code as follows:
If IsNumeric (ID) =false then Exit Sub
strSourceFile = Server.MapPath (dataxml "/advertisement/" id "/adv.xml")
Set objxml =server.createobject ("Microsoft.XMLDOM") ' creates an XML pair like
Objxml.load (strsourcefile) ' reads the XML file into memory
Set Xml=objxml.documentelement.
Method 1: Read the XML content from the remote server to dataset. At the beginning, the data is read directly using the readxml (URL) method of dataset. The error "407 requiring proxy authentication" always occurs and is used in
Program Global Proxy can be declared in.
Proxy
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHi
Four ways in which Java reads XML files XML code
version="1.0" encoding="GB2312"?>
A1234
Henan province Zhengzhou
B1234
Erqi District, Zhengzhou city, Henan Province
The first method of DOM implementation is import java.io.File; Import JAVAX.XML.PARSERS.DXML file The first method o
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.