There are four types of parsing xml files in java. DOM, SAX, DOM4J, and JDOM. In my first article, I will introduce how to use Jdom to parse XML. I think one of these four learning methods is enough. The other three parsing ideas are not much different. In addition, you can query the advantages and disadvantages of the
Use xpath to parse xml and javaxpathxml in Java
Xpath is a language used to search for information in xml documents. Xpath is used to navigate through elements and attributes in XML documents. The return value may be a node, a node set, text, and a mixture of nodes and text.
Although there are already two standard parsing methods for DOM and sax in Java
But it is not easy to operate, for a beginner like me, part of the code is living nausea
To this end, the great third party development team developed jdom and DOM4J tools
Given the current trend, we are here to talk about the basic usage of dom4j, not involving complex operations such as recursion.
DOM4J is a lot of use, the official online example is a little obscure
in advance, occupy less resources; SAX parser code is smaller than DOM parser code, suitable for applets, download. Cons: not persistent; After the event, if the data is not saved, then the data is lost, stateless, only the text can be obtained from the event, but the text is not known which element; use case: Applet; only a small amount of content in an XML document is seldom returned, and less machine memory is available.3.DOM4J Generating and pars
Reference articles1:http://blog.csdn.net/clemontine/article/details/530113622:http://www.jb51.net/article/98456.htmhttp://blog.csdn.net/javawebrookie/article/details/49560643Parsing XML in 1.DOM modeDom parsing is an XML file loaded into memory, assembled into a DOM tree, and then through the relationship between nodes and nodes to parse the
The above is my final running result.
In order to consolidate the learning in the future, we will paste it here for future reference.
1. Library. xml:
2. domparse. java: (write it in Notepad.) import Java. io. fileinputstream; import Java. io. ioexception; import Java
When the Java program parses the XML file, if the DTD is specified in the XML file, the DTD file is downloaded from the specified URL by default, but in many cases, if the network is not connected, or because of a firewall reason, the DTD file cannot be downloaded to cause the report connection timeout exception and parsing the
Currently, there are many methods of using sax. The main difference with Dom is that it reads XML files in a row for analysis. It is suitable for large files. Dom is a one-time read into the memory and obviously cannot deal with large files. here we use SAX parsing. Due to the continuous development of the SAX Parser, many articles on the Internet are aimed at the old version. if you use jdk1.4, you can refer to the article about processing
special sax interface in a Java class package, which is located in the org. xml. Sax package. This interface encapsulates some event processing methods. When the XML Parser begins to parse the XML input file, it will encounter some special events, such as the beginning and
Dom is a powerful parsing tool for small documents
Why? Because it loads the entire xml file into the memory to form a Document Object Tree
In a word, it sounds weird, but it is quite convenient to use it to read some small things than Sax.
As for its addition, deletion, and so on, I am not planning to write it. When I read the tutorial, I almost threw out the code.
Because of this, only later tools such as jdom and dom4j existed ......
Not to mention
How do you parse an XML file using Jdom in Java? The following small series on the example for you to introduce a detailed. Need friends can refer to the next
Jdom is an open source project that uses pure Java technology to parse, generate, serialize, and manipulate
There are four ways in which Java parses XML classics:1.dom 2.sax 3.jdom 4.dom4j personally feel dom4j useful, but I only used jdom.Android I know in two ways sax and pullSAXthe way is characterized by the need to parse out the entire document before it is returned, if in aXMLin the documentation we only need the previous part of the data, but usingSAXThe entire
Search on the Internet, the method of parsing XML is roughly as follows:
Xmlio, Xerces, JDOM, dom4j, XOM, JiBX, Kxml, XMLBeans, Jconfig, XStream, piccolo, Nanoxml, XP Parser, Commons-digester, Nunnimjax, Crimson, Jox, JaxMe, Xmlconfigreader, Woodstox, Xalan
I've used the JIBX, XMLBeans, JDOM, dom4j, and Java-included XPath myself, where the JIBX and XMLBeans principles are similar, and the JDOM and dom4j pr
Java parses XML in two ways:
** Dom
** Sax
Example:
Dom mode:
Load XML, and create a DOM tree corresponding to the XML file in the memory.
Obtain the required information based on node and nodelist In the DOM tree.
public boolean parserXml(InputStream is) throws Exception {DocumentBuilderFactory factory = Documen
Jdom is an open source project that uses pure Java technology to parse, generate, serialize, and manipulate XML documents based on a tree-structured architecture. Jdom directly for Java programming services. It leverages the many features of the more powerful Java language (
Http://developer.51cto.com/art/200903/117512.htmXML has now become a universal Data Interchange format, its platform-independent, language-independent, system-independent, to the data integration and interaction brought great convenience. The syntax and technical details of the XML itself need to be read in the relevant technical literature, which includes the DOM (document Object Model), the DTD (document Type Definition), SAX (Simple API for
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.