Java XML Extensible Markup Language (extensible Markup Language)

Source: Internet
Author: User
Tags xpath

One, XMl

1.1. Introduction to XML:

XML refers to Extensible Markup Language (extensible Markup Language), which is a markup language that is much like HTML. XML is designed to transmit data, focus on the content of the data, and HTML is designed to display the data, focusing on the appearance of the data. XML doesn't do anything, it's just designed to structure, store, and transfer information.

1 <mail>2     <from>tom</from>3     <to>lily</to>4 this      weekend!</detail>5 </mail>

1.2. XML Structure:

XML is a tree structure. A tree is an important nonlinear data structure, visually, it is the structure of data elements (called nodes in a tree) organized by branches, much like the trees in nature.

The XML document must contain the root element, which is the parent element of all other elements. The elements in the XML document form a document tree that starts at the root and expands to the bottom of the tree.

All elements can have child elements, and terms such as parent, child, and sibling are used to describe the relationship between elements. The parent element has child elements, and child elements on the same level become siblings (brothers or sisters). All elements can have text content and attributes (similar to elements in HTML)

1<bookstore>2<book category= "Children" >3<title lang= "en" >harry potter</title>4<author>j K. rowling</author>5<year>2005</year>6<price>29.99</price>7</book>8<book category= "Cooking" >9<title lang= "en" >everyday italian</title>Ten<author>giada De laurentiis</author> One<year>2005</year> A<price>30.00</price> -</book> -</bookstore>

1.3XML Syntax Rules:

It defines the version of the XML (1.0) and the encoding (UTF-8) character set used.

All XML elements are paired and there is a start tag that must have a close tag.

XML tags are case sensitive, and labels are different from labels.

The XML document must have a root element, and if the tag needs to be nested, it must be nested correctly, and the label opened inside the inner layer must be closed on the inner layer.

XML tags if you need to add an attribute, the attribute value must be quoted.

The syntax for writing comments in XML is very similar to the syntax of HTML, both.

In XML, spaces are preserved, unlike HTML, where more spaces are eventually merged into one.

1.4XML naming rules:

Names can contain letters, numbers, and other characters

Names cannot start with numbers or punctuation marks

The name cannot begin with the letter XML (or XML, XML, and so on)

Name cannot contain spaces

You can use any name without a reserved word.

1.5XML elements:

A, start tag
B, element attributes (character attributes, nested elements, entities, CDATA)
B, element content

1.6DTD:

The role of a DTD (document type definition) is to define a legitimate building block for an XML document. XML with the correct syntax is called "well-formed" XML, and we can validate the XML as "legitimate" through a DTD.

1.7 Why DTD is used:

With DTDs, each XML file can carry a description of its own format, through DTDs, independent groups can use a standard DTD to exchange data consistently, and applications can use a standard DTD to validate externally received data, as well as to validate their own data using DTDs.

1.8 Manipulating XML using DOM4J:  

  1. Create Document Object

    1 Document document = documenthelper.createdocument (); 2 3 // root element node

  2. Gets the document object when reading an XML file

    1 New Saxreader (); 2 3 Document document = Reader.read (new File ("Student.xml"));

  3. Gets the Document object when the string is parsed to XML

    1 String text = "Tom"; 2 3 Document document = Documenthelper.parsetext (text);

1.9xPath:

An XPath path expression

XPath uses path expressions to pick nodes or set of nodes in an XML document that are very similar to the expressions we see in a regular computer file system.

Xpth node:

In XPath, there are seven types of nodes: elements, attributes, text, namespaces, processing directives, annotations, and document (root) nodes. The XML document is treated as a node tree, and the root of the tree is called the document node or root node.

Sax provides an event-driven model for parsing XML documents that the SAX parser uses callback mechanisms to notify client applications when different XML syntax structures are identified

Java XML Extensible Markup Language (extensible Markup Language)

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.