Introduction and development of XML

Source: Internet
Author: User
XML: ExtensibleMarkupLanguage (Extensible Markup Language) is a metalanguage used to define other languages. its predecessor is SGML (StandardGeneralized Overview

XML: the abbreviation of Extensible Markup Language (Extensible Markup Language). It is a metalanguage used to define other languages. its predecessor is SGML (Standard Generalized
Markup Language (Standard General Markup Language ). It does not have a tag set or grammatical rule, but it has syntax rule ).
Any XML document must be well-formed for any type of applications and correct parsing, that is, each opened tag must have a matched end tag.
The statement structure should comply with the technical specifications. XML documents can be valid, but they are not necessarily required. The so-called valid document refers to its compliance with the document
Document of Type Definition (DTD. If a document complies with a schema, this document is "schema valid )".

XML is a markup language similar to HTML. XML is designed to transmit data rather than display data. XML labels are not predefined. You need to customize the tag. XML is designed to be self-descriptive. XML is W3C recommendation standard

XML is used to create a new Internet language.

Many new Internet languages are created using XML:

Examples include:

XHTML-latest HTML version, WSDL-used to describe available web services, WAP and WML-markup language for handheld devices, RSS-used for RSS feed language,

RDF and OWL-used to describe resources and ontology, and SMIL-used to describe web-targeted multimedia

Here is a common case:

 
    
   Everyday Italian   Giada De Laurentiis   
   
    2005
      
   
    30.00
    
  
    
   Harry Potter   J K. Rowling   
   
    2005
      
   
    29.99
    
  
    
   Learning XML   Erik T. Ray   
   
    2003
      
   
    39.95
    
  
 

It can be explained as follows:

XML naming rules

XML elements must follow the following naming rules:

  • The name can contain letters, numbers, and other characters.

  • The name cannot start with a number or punctuation.

  • The name cannot start with the character "xml" (or XML or Xml ).

  • The name cannot contain spaces.

You can use any name without reserved words.

What is an XMLHttpRequest object?

The XMLHttpRequest object is used to exchange data with the server in the background.

The XMLHttpRequest object isDeveloper's dreamBecause you can:

  • Update the webpage without reloading the page

  • Request data from the server after the page has been loaded

  • Receive data from the server after the page is loaded

  • Send data to the server in the background

All modern browsers support XMLHttpRequest objects.

Create an XMLHttpRequest object

All modern browsers (IE7 +, Firefox, Chrome, Safari, and Opera) have built-in XMLHttpRequest objects.

With a simple line of JavaScript code, we can create an XMLHttpRequest object.

Syntax for creating an XMLHttpRequest object:
xmlhttp=new XMLHttpRequest();

Why use the XML editor?

XML is a very important technology today, and development projects are using these XML-based technologies:

  • Use XML Schema to define XML structures and data types

  • Use XSLT to convert XML data

  • Use SOAP to exchange XML data between applications

  • Use WSDL to describe network services

  • Use RDF to describe Network Resources

  • Use XPath and XQuery to access XML data

  • Use SMIL to define graphics

XSLT

XSLT (eXtensible Stylesheet Language Transformation) is a Language used to convert the XML document structure.

Process of XSL:

First, construct the source tree according to the XML document, and then convert the source tree to the result tree according to the XSL rules. after the result tree is generated, explain it, format is a suitable format for displaying, printing, or playing.

Comparison between XSLT and CSS:

CSS

XSLT

Easy to use

Complex application

Elements cannot be sorted, added, or deleted.

Elements that can be sorted, added, or deleted

You cannot access information except elements in a document.

Access Other information

Memory usage is relatively small

Use more memory and processor capabilities

Different from XML syntax

Same syntax as XML

XPath basics

XPath is a language used to locate and search for information in XML documents. XPath can be used to traverse elements and attributes in XML documents, which is the basis of advanced XML applications.

XPath mainly has four data types: (1) node set. (2) Boolean type. (3) string type. (4) numerical type.

In XPath, nodes can be divided into seven Node types: (1) Root Node ). (2) Element node ). (3) Text node (Text Nodes ). (4) Attribute Nodes ). (5) Namespace node (Namespace Nodes ). (6) Processing Instruction Nodes ). (7) Comment node (Comment Nodes ).

XPath node relationship: (1) parent (parent ). (2) child (children ). (3) siblings (sibling ). (4) advanced generation (ancestor ). (5) descendant (descendant ).

XPath expressions

XPath regards XML documents as a hierarchy tree composed of nodes, and locates specific nodes in the tree by writing XPath expressions.

XPath path expression:

Expression

Description

Nodename

Select all child nodes of this node

/

Select from the root node, absolute path, indicating the root node of the current document

//

Select from any node. the relative path indicates all nodes in the current document.

.

Select current node

..

Select the parent node of the current node

@

Select attributes

Example

 
     
          
   RESTful Web Services        
   
    
29.00
       
      
          
   C # Programming basics        
   
    
46.00
       
  
 

Resolution:

Bookstore

Select all subnodes of the bookstore element

/Bookstore

Select the root node bookstore element

/Bookstore/book/price

Select all price elements of all book elements under the bookstore element

/Bookstore/book /*

Select all child elements of/bookstore/book

Bookstore/book

Select all book child elements under the bookstore element

// Bookstore

Select all the bookstore elements in the document, no matter what level it is

Bookstore // book

Select all book elements under the bookstore element, no matter where they are located under the bookstore

/Bookstore/*/price

Select the sub-element of the bookstore that contains price as the sub-element.

//*

Select all elements in the file

// @ Lang

Select all properties named lang

Predicates:

Path expression

Description

/Bookstore/book [last ()]

Select the last book element that belongs to the bookstore sub-element

/Bookstore/book [last ()-1]

Select the penultimate book element that belongs to the bookstore sub-element

/Bookstore/book [position () <3]

Select the first two sub-elements of the bookstore

// Title [@ lang]

Select all title elements with properties named lang.

// Title [@ lang = "en"]

Select all title elements and these elements have the lang attribute whose value is eng.

/Bookstore/book [price> 15.00]

Select the book element of all bookstore elements, and the value of the price element must be greater than 15.00

/Bookstore/book [price> 15.00]/title

Select the title element of the book element in all the bookstore elements, and the value of the price element must be greater than 15.00

// Title [@ *]

Select all title elements with attributes

To select more than one path, you can use the "|" operator in the XPath expression:

Path expression

Description

// Book/title | // book/price

Select the title and price elements of all book elements

// Title | // price

Select all the title and price elements in the document

/Bookstore/book/title | // price

Select the title element of all the book elements that belong to the bookstore element and all the price elements in the document.

Common operators of XPath expressions:

Operator

Description

Instance

|

Calculate two node sets

// Book | // cd, returns all node sets with the book and cd elements

+

Addition

6 + 4,

-

Subtraction

6-4

*

Multiplication

6*4

P

Division

8 p 4

=

Equal

Price = 15

! =

Not equal

Price! = 15

<

Less

Price <15

<=

Less than or equal

Price <= 15

>

Greater

Price> 15

> =

Greater than or equal

Price> = 15

Or

Or

Price = 15 or price = 35

And

And

Price> 15 or price <35

Mod

Calculate the remainder of the division

5 mod 2

Example

private void button1_Click(object sender, EventArgs e)          {              XmlDocument doc = new XmlDocument();              doc.Load(@"..\..\CD.xml");                XmlElement root = null;              root = doc.DocumentElement;                XmlNodeList listNodes = null;              listNodes = root.SelectNodes("/bookstore/book/price");              foreach (XmlNode node in listNodes )              {                  richTextBox1.Text += node.InnerText + "\n";              }          }

Result:

29.00

46.00

The above is the detailed description of XML introduction and development (text). For more information, see other related articles in the first PHP community!

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.