XML technology Preview

Source: Internet
Author: User
Tags xml parser
1. display XML
The XML document only describes the data content, and its display function is completed by the style sheet. When style sheets are used, the output platform is not limited to a display, but can be a printer, a plotter, or a multimedia player. One of the major advantages of using an independent style sheet file to create a display format is that different styles can be developed for the same data file and applied in different occasions, this enables more rational and targeted data presentation, improving data reusability.
Currently, W3C officially recommends two types of style sheet standards: Cascading Style Sheet (CSS) and extensible style sheet language XSL.
CSS was originally used to define the HTML document display format and can now be used to make simple style planning for XML documents. CSS is widely used in HTML, but it is slightly inadequate in text placement, determining the display mode based on text content, and sorting data.
XSL effectively solves these CSS problems. The most common function of XSL is to convert the XML tag to the HTML Tag and display the output. In addition, XSL can also convert XML documents to any structure document in other formats. This function has a good application prospect in the B2B business model.
XSL uses pattern matching to select elements/attributes to be processed in the XML document, and then develops conversion rules for these specific objects. With XSL, we can also add new elements/attributes, re-Sort all elements/attributes, process cyclically, and determine conditions. Program To adapt to various complex requirements.
The format for referencing XSL in XML documents is as follows:
<? XML-stylesheet type = "text/XSL" href = "employees. XSL"?>
An XML document can reference only one XSL style sheet. When processing XML documents, the XML Parser loads the specified XSL style sheet after processing instructions, and then converts the sheet according to the rules.
Ii. Bind XML
There are three data transmission methods between the Web server and the client: HTML pages, XML documents, and XML data islands. XML data island directly embeds XML data into HTML documents using specific tags. Using data island as an interactive means not only can make the data have Certain semantic information, but also maintain some of the original characteristics of HTML, such as using the user-side script program to achieve dynamic information exchange.
The implementation method of XML data island is to use the <XML> tag in the HTML document. Code There are two ways of embedding: direct embedding (for example, 1) and external referencing (for example, 2 ).
Example 1:
<XML id = "myxmldata">
<? XML version = "1.0"?>
...... XML definitions ......
</XML>
Example 2:
<XML id = "myxmldata" src = "http://www.microsoft.com/myxmldata.xml">
</XML>
After inserting the data island, you can link the elements in XML with the HTML elements and display the XML data using the HTML representation. This link is called binding. The binding method can be divided into two types based on the nature of HTML elements: Single-value objects and table objects.
To bind data to a single-value object, you must set the datasrc and dataworkflow attributes in the HTML element. The datasrc attribute uniquely identifies an XML data island object and must be prefixed with "#". The dataworks attribute identifies an element object in the data island. In Example 3, an HTML text input box is bound to the <salary> element.
Example 3:
<Input type = "text"
Datasrc = "# myxmldata"
Dataworks = "salary">
Table objects are mainly associated with <Table> tags in HTML. Generally, you can use ActiveX controls such as DSO (data source object, data source object) to process table data more conveniently and effectively. The detailed usage will be detailed in the future.
3. Access XML
Document Object Model (DOM) is an application interface (API) for application development and programming of Web documents ), is a cross-platform, language-independent interface specification published by W3C.
Dom uses Object Models and a series of interfaces to describe the content and structure of XML documents, that is, using objects to model documents. The basic functions of this object model include:
● Interface for describing document representation and operations;
● Interface Behavior and attributes;
● Relationship between interfaces and interoperability.
Dom parses structured XML documents. All the instructions, elements, entities, attributes, and other individuals in the documents can be represented by object models. The logical structure of the entire document is similar to a tree. The generated object model is the node of the tree. Each object contains both methods and attributes.
With Dom, developers can dynamically create XML documents, traverse structures, add, modify, and delete content. Dom's object-oriented feature saves a lot of effort in processing XML parsing-related transactions and is a powerful programming tool that conforms to the code reuse idea.
Iv. Verify XML
XML documents must strictly abide by the syntax specifications, that is, they must all be "well-formed ". At the same time, XML documents should also comply with semantic specifications, that is, "valid ". The validation of XML documents is called the validation of XML ).
"Well-formatted" is the most basic requirement for XML documents. All "well-formed" XML documents can be parsed by the XML parser to generate an object tree for further processing. In addition, "valid" XML must be "well-formed ". On this basis, we also need to observe the DTD or XML Schema syntax. Only in this way can we ensure the ease of use of XML documents, while fully reflecting the relationship between data information, so as to better describe data.
DTD can define the vocabulary and syntax of XML documents. Using a regular expression, DTD not only describes which elements in an XML file are required, which are optional, but also the attributes that an element can contain, it can also depict the structure information between elements. For example, which child elements can be nested in an element, the number of child elements, the order of appearance, and whether the element is optional.
The typical DTD format is as follows:
● Use the doctype declaration as the starting sign to tell the parser that the following content belongs to the DTD;
● The DTD name after doctype must be exactly the same as the root element in the XML document, followed by a "[", followed by the DTD body.
DTD can be used in two ways: Nested (for example, 4) and referenced (for example, 5 ). Their locations in XML documents must be before the emergence of the root element.
Example 4:
<? XML version = "1.0"?>
<! Doctype employees [
...... Element and ATTLIST definitions ......
]>
<Employees>
...... XML data ......
</Employees>
Example 5:
<? XML version = "1.0"?>
<! Doctype employees system "employees. DTD">
<Employees>
...... XML data ......
</Employees>
Currently, DTD is the only formal specification recommended by W3C to verify the effectiveness of XML documents, but it also has many shortcomings:
● The DTD is too complex. It takes a certain amount of time and effort to familiarize yourself with its syntax and tag set. Besides, the DTD adopts non-XML syntax rules and cannot be operated and processed using XML tools;
● DTD does not support data type definitions. The defined data types are limited. They are all set up for attributes and cannot meet the diversified data types required by e-commerce and other Web applications;
● The expansion mechanism is complex and fragile. The biggest drawback is that it cannot express the relationship between elements;
● DTD does not support namespaces.
The above defects prompted W3C organizations to seek a new mechanism to replace DTD. Among the many standards, the XML schema proposed by Microsoft is more eye-catching. It fully complies with XML syntax, rich data types, good scalability, and is easy to be processed by XML parsers such as Dom.
Finally, we will introduce xmlint.exe, a small tool for XML verification. It can be used to verify that the XML document is "well-formatted" and "valid". The usage is as follows:
Xmlint c: \ my_xml \ *. xml
<! -- Verify whether all XML documents are "valid" -->
Xmlint-w c: \ my_xml \ *. xml
<! -- Only verify whether the format is "good" -->
You can visit the following URL to download the software:
Http://msdn.microsoft.com/downloads/tools/xmlint/xmlint.asp

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.