introduced. We will use these three parsing techniques to accomplish a common task.
We create a new project with the following project structure:
I will place an XML document books.xml in the assets directory of the project, as follows:
Then we use the above three kinds of parsing technology to parse the document, get a List
Package Com.scott.xml.model;
public class Book {
pri
Tags: XML file finereport program data setin a database table, where the fields XML is stored in XML Format data in table Xmltest. When you use this table for report authoring, you need to read the values stored in the XML field as the report data source.650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/8D/89
js|xml| asynchronous 1. Create a new VS2003 Web project, named Xmltest
2. Delete all the contents of the WebForm1.aspx in the engineering catalogue, leaving only one statement at the top:
3. Modify the contents of the WebForm1.aspx.cs and add in Page_Load:
XmlDocument doc=new XmlDocument ();
String xmlfile=string. Empty;
xmlfile=context.request.physicalappli
(0); if (node. getChildNodes (). item (0). getNodeValue ()! = Null) {result = (node. getChildNodes ()). item (0 ). getNodeValue (). trim () ;}}}} catch (Exception e) {System. out. println ( quot; getNodeValueFromDom error = quot; + e. toString (); e. printStackTrace ();} return result ;}}
Java uses dom4j to read xml (element attributes of the xml file are not
PackageJaxp (Sun), Jdom, dom4j, Pull (Android SDK comes with)(1) Jaxp-dom parsing XML (curd)JAXP (Java API for XML processing)JAXP is a set of XML parsing APIs provided by SunJaxp is a good way to support DOM and sax parsingThe JAXP development Pack is part of the J2SE, including the following packages or sub-packages
Sax is an XML parser that is fast and consumes less memory, and is ideal for mobile devices such as Android. The Sax parsing XML file takes event-driven, that is, it does not need to parse through the entire document, and in the process of parsing the document in content order, sax determines whether the currently-read character is legitimate in the
Com.xsjayz.xml;import Java.io.inputstream;import Java.util.list;public interface Bookparser {/** * Parse input stream Get a collection of book objects * * @param is * @throws Exception */public listBook:Package com.xsjayz.xml;/** * Book's model class, which defines all the states, accessors, and modifiers of book, overrides the ToString method */public class Book {private int id;private String name;privat
-minded, more readable, but performance slightly slower than the first way, and not strong flexibility. XML parser supports PHP4 for use with older versions of the system. For the PHP5 environment, consider the following method as a priority.2. SimpleXMLSimpleXML is an easy-to-use XML toolset provided after PHP5 that transforms XML into an easy-to-handle object o
parse any XML document, load the XML document into memory, occupy large memory, and randomly access
Public class Recursiondom_xml
{
public static void Main (string[] args) throws Exception
{
//1. Getting the DOM parser factory
Documentbuilderfactory dbf = Documentbuilderfactory.newinstance ();
/
Parse XML with JDOM
All classes of the JDOM model are in org. JDOM. * In this package, org. JDOM. input. * This package contains the JDOM parser. The dombuilder function is to parse the document of the DOM model into the document of the JDOM model; the function of saxbuilder is to parse the
Example:
DOM XML parser functions are part of the core of PHP. You can use these functions without installation.XML fileThe following XML file will be used in our example:
The code is as follows
Copy Code
Loading and exporting XMLWe need to initialize the XML parser, load the XML
of code, but clear-minded, more readable, but performance slightly slower than the first way, and not strong flexibility. XML parser supports PHP4 for use with older versions of the system. For the PHP5 environment, consider the following method as a priority.
2. SimpleXML
SimpleXML is an easy-to-use XML toolset provided after PHP5 that transforms XML into an ea
Parse XML files using JDOM
JDOM is an open-source project that uses the pure Java technology to parse, generate, serialize, and operate XML documents based on the tree structure. JDOM directly serves Java programming. It effective
2017/4/26-DOM Parse XML file, 201726-dom
DOM parsing XML
1,Analysis
DOM is an XML parsing API that comes with JAVA. DOM first loads all XML files into the memory, and then creates a DOM tree in the memory to generate each Node on
::removeattribute (string $name)
String $name: Name of the property to be removed
15. Get Properties
string Domelement::getattribute (String $name)
String $name: Property name of the property value to get
DOMDocument is also part of the DOM extension introduced after PHP5, w
three functions return the SimpleXMLElement object, and the read/add of the data is done through the simplexmlelement operation.
$string =
The advantage of SimpleXML is that it is easy to develop, and the downside is that it will load the entire XML into memory before processing it, so it may be too weak to parse an XML
($ _ xml); // create an object to parse an xml string$ _ Sxe-> asXML ('test. xml'); // generate an xml file2. load XML files$ _ Sxe = simplexml_load_file ("test.
1. Using dom to parse xml files in addition to using SAX to parse XML files, you can also use the familiar DOM to parse XML files. When DOM parses an XML file, it stores all the content
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.