start, end, text, start, or end of an element, it sends events and programmers write code to respond to these events and save data.
Advantage: the entire document does not need to be transferred in advance, which consumes less resources.
Disadvantages: it is not persistent. After an event, if no data is saved, the data is lost; stateless; only the text can be obtained from the event, but the element of the text is unknown;
Usage scenarios: only a small amount of content in the
Currently, there are many techniques for parsing XML in Java, such as Dom, SAX, JDOM, dom4j, and the advantages and disadvantages of these 4 kinds of parsing XML document technologies are described below.First, define an interface XmlDocument that operates an XML document, which defines the interface for creating and p
, and attribute values.Important JDOM classes:org.jdom2.input.DOMBuilder:Use the DOM parsing mechanism to parse XML and convert it to a JDOM Document object.org.jdom2.input.SAXBuilder:Use the SAX parsing mechanism to parse XML and convert it to JDOM Document.org.jdom2.input.StAXEventBuilderAndorg.jdom2.input.StAXStream
The pull XML parser has already been integrated into the Android SDK by Google, which is the parser recommended by Google.If we want to use pull method to generate XML file and parse XML file in Java Desktop, J2ME, etc., we need to use KXML2;Kxml parser is a small parser bas
and switch to the directory where the. xsd file was generated in the previous step.Complete the conversion with the XJC command:XJC the full destination package name of the. xsd full file name –p conversion to convert. Example: XJC atmradi_param.xsd–p Xmlbean.atmradiThe resulting results are as follows:A lot of. java files have been generated in the Xmlbean folder at this time6 Change the type of the variable in the.
{Persister.write (B1,NewFile ("B.xml")); Persister.write (B1, System.out); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}The B.xml file is written here, and the console is also written for easy viewing, and the console output is as follows:is not like Hypertext language HTML format ~Run interface, parse function file App.java: PackageCom.newer.xml;ImportJava.io.File;ImportOrg.simpleframework.xml
structure:
This article uses the Java language to generate and parse XML documents for DOM and sax.First, define an interface for manipulating XML documents XmlDocument it defines the interface for establishing and parsing XML documents.
page gets the XML file, preferably displaying the node information in the XML file on the page.4, as the configuration information data for some applications. Common Web. XML, such as Java EE, is used to configure the server.5. xml format for some other documents. such as W
As we all know, there are more and more ways to parse XML, but there are four main approaches: DOM, SAX, Jdom, and dom4j
The following first gives the jar package download addresses for these four methods
DOM: It's all in the Java JDK now, in the Xml-apis.jar bag.
sax:http://sourceforge.net/projects/sax/
Jdom:http:
structure:
This article uses the Java language to generate and parse XML documents for DOM and sax.First, define an interface for manipulating XML documents XmlDocument it defines the interface for establishing and parsing XML documents.
Java Web Learning notes -- use Jdom to parse xml and javawebjdom
I. Preface
What is Jdom?
Jdom is an open-source project that uses java-only technology to parse, generate, serialize, and operate XML documents based on the tree st
to be frequently changed in the service.
The SAX Parser uses an event-based model, which is used to parse XMLA document can trigger a series of events. When a given tag is found, it can activate a callback method to tell the method that the tag has been found. SaxMemory requirements are usually relatively low, because it allows developers to determine the tag to be processed by themselves. Especially when developers only need to process part of the d
[Path to Java Development] (12) Parse XML documents using JDOM and DOM4J1. parse XML documents using JDOM1.1 Introduction JDOM is an open-source project. Based on the tree structure, JDOM uses JAVA-only technology to
Brief introductionDOM4J is an open source XML parsing package produced by dom4j.org. This sentence is too official, let's take a look at the official explanation. Such as:DOM4J is an easy-to-use, open-source library for parsing languages such as Xml,xpath and XSLT. It is applied to the Java platform, uses the Java Coll
(attributes.getqname (0)
+ attributes.getvalue (0));
}
}
}
public void characters (char[] ch, int start, int length)
Throws Saxexception {
System.out.println (New String (CH, start, length));
}
}
3.dom4j generate and parse XML documents
Dom4j is a very, very good Java XML API with excellent performanc
XML 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
Java Pull method to generate and parse xml files, pullxml
Google has already integrated the Pull XML Parser into the android sdk, which is officially recommended by google.
If we want to use the Pull method to generate xml files and par
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.