XML technology preview

zhaozj2021-02-11  187

XML Technology Preview - XML ​​Technical Series Lecture (2)

Beijing University of Posts and Telecommunications

Application and development

Display XML

The XML document itself describes only the data content, which is done by the style sheet. When using style single technique, the output platform is not limited to the display, which can be a printer, a plotter, or a multimedia player. A large advantage of using independent style single files to formulate display formats is: Different style styles can be developed for the same data file, which makes data more reasonable, more targeted, and improved data. Reuse.

At present, there are two types of style single standards recommended by W3C: one is a laminated style CSS (Cascading style Sheets); the other is an extensible style single language XSL.

CSS was originally used to develop an HTML document display format, and now you can now use a simple style plan for XML documents. The application of CSS in HTML is extremely wide, but it is slightly insufficient in terms of textual replacement, determine the display mode in accordance with the text content, slightly insufficient display function for sorting data.

The XSL has better solves these problems of CSS. Its most commonly used function is to convert XML's assignment into the html gates and display output. Moreover, XSL can also convert an XML document to any other formatted structure document. This feature has a good application prospect in the business model of B2B.

XSL uses the mode matching method, selects the elements / properties that need to be processed in the XML document, and then develop corresponding conversion rules for these specific objects. With XSL, we can also add new element / properties, reordering all element / properties, loop processing, conditional judgment and other programming control, to adapt to a variety of complex demand.

The format of the XSL is referenced in the XML document is as follows:

An XML document can only reference an XSL style sheet. When the XML parser is in processing the XML document, after the processing instruction is encountered, the specified XSL style is loaded, and then the corresponding conversion processing is performed according to the rules.

Bind XML

There are three data transfer methods between the web server and the client: HTML page, XML documentation, and XML data island. Among them, XML data island embeds the XML data directly into the HTML document through a specific label. The data island is used as an interaction method, which not only makes a certain semantic information, but also maintains some of the original features of HTML, such as utilizing user-end scripts implement dynamic information exchange, etc..

The implementation method of XML data island is to use the tag in the HTML document. There are two embedded methods of code: direct embedding (as in Example 1) and external references (as in Example 2).

Example 1:

... XML definitions ......

Example 2:

After inserting the data island, you can link the elements in the XML to the HTML element, and the XML data is displayed using the HTML manifestation, which is called binding. The binding mode can be divided into two: single-value objects and table objects according to the nature of the HTML element.

The data binding of single-value objects requires setting DataSRC properties and DataFLD properties in the HTML element. The DataSRC property is the unique identifier of the XML data island object, and must add a prefix "#"; the DataFld property identifies the element object in the data island. Example 3 is to bind an HTML text input box with the element. Example 3:

Datasrc = "# myXmldata"

DataFld = "Salary">

As for the table object, it is mainly binding to

tags in HTML. Generally, the table data can be handled more easily and efficiently by means of ActiveX controls such as DSO (Data Source Object, Data Source Object). Specific use methods will be described in detail in future content.

Access XML

Document Object Model is referred to as DOM, is an application development for web documentation, programming application interface (API), is a cross-platform, and language-independent interface specification published by W3C.

The DOM uses an object model and a range of interfaces to describe the contents and structures of the XML document, which uses objects to model documents. The basic features implemented by this object model include:

● Describe the interface of document representation and operation;

● The behavior and attributes of the interface;

● The relationship between the interfaces and interoperability.

DOM parsing structured XML documents, all individuals, including instructions, elements, entities, properties, etc. in the document can be represented by an object model. The logical structure of the entire document is similar to a tree. The generated object model is the node of the tree, and each object contains simultaneous methods and properties.

With DOM, developers can dynamically create an operation of XML documents, traverse structures, add / modify / delete content. The DOM object-oriented characteristics make people save a lot of effort when handling and XML parsing, is a powerful programming tool that meets the code reusability ideas.

Verify XML

The XML document must strictly abide by the syntax specification, that is, must be "good format". At the same time, XML documents should also meet semantic specifications, ie "effective". Check for the validity of XML documents is called "Validation" for XML.

"Good format" is the most basic requirement for XML documents. Any "well-form" XML document can be parsed by the XML parser to generate an object tree for further processing. And "effective" XML must be "good format". On this basis, the grammatical provisions of DTD or XML Schema can also ensure that the readability of the XML document can be sufficiently reflected in the relationship between data information, thereby better describing data.

DTD can define the vocabulary and syntax of the XML document. Using regular expressions, DTD can explain which elements in the XML file are essential, which are optional, and the elementality such as the element itself, etc., the structure information between the elements can also be depicted. For example, one element can nest which sub-elements, the number of child elements, and the order of appearance, whether or not it is optional.

Typical DTD formats are as follows:

● Declare the starting flag with DOCTYPE, tell the parser The following content belongs to DTD;

● The DTD name after DOCTYPE must be exactly the same as the root element in the XML document, followed by a "[" number, next is the DTD body.

DTD has two ways: Embedded (as Example 4) and the reference (as in Example 5). They must be in the XML documentation before the root element appears.

Example 4:

...... Element and attlist definitions ......

]>

... XML Data ......

Example 5:

... XML Data ...

At present, DTD is the only formal specification for the validity of the W3C recommendation of XML document, but it also has many deficiencies:

● DTD is too complicated. To be familiar with its grammar, the marker collection requires certain time and energy, and the DTD uses non-XML syntax rules, and cannot use the XML tool to perform operational processing;

● DTD is insufficient to define data types, defined data types are limited, and it is set up for attributes, which cannot meet the rich data types of web applications such as e-commerce;

● The expansion mechanism is complicated, and it is also very fragile, the biggest disadvantage is the relationship between the incompatibility between the elements;

● DTD does not support the mechanism of namespaces.

The above defects have prompted W3C organizations to seek a new mechanism to replace DTD. Among the many standards, Microsoft's top-bearing XML Schema is more compelling. It has the advantages of fully compliant xml grammar, rich data type, good scalability, and XML parser processing that is easy to be Dom.

Finally, a gadget for XML verification: XMLint.exe. It can be used to verify that the XML document is "good format" and "effective", the usage is as follows:

XMLint C: / my_xml / *. XML

XMLINT -W C: / my_xml / *. XML

You can download the following URL to download the software:

转载请注明原文地址:https://www.9cbs.com/read-5262.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.059, SQL: 9