System Architect study note _ Chapter 8 _ serialization

Source: Internet
Author: User
Tags processing instruction xml attribute xml parser xsl xslt

8.1 XML Overview

The Extensible Markup Language (xml) is a subset of the standard General Markup Language (SGML). XML can be used to develop a markup language, its elements and attributes are mostly defined for specialized industries and industries.

Supports the unified character encoding (UCS), making XML an international standard. Both XML and HTML support style sheet (style sheet ).

8.1.2 tag syntax

The structure of XML elements is basically the same as that of HTML elements. tags are defined using angle brackets, but the similarities between the two are the same.

Different from HTML, almost all XML tags are case-sensitive, mainly to meet the design objectives of XML internationalization and to simplify the processing process.

Non-English letters may not have the corresponding upper or lower case. Merging may have many defects.

1. Character

The characters specified in XML are both in the 16-bit Unicode 2.1 character set.

2. Name

The XML name must start with a letter, underline, or colon, followed by a valid name character (number, minus sign, point ).

In practice, the colon should not be used unless it is a delimiter used for namespace modification.

Letters are not limited to ASCII code, which is very important.

8.1.3 documentation

Formal XML format:

1. An optional prolog)
2. Document body)
3. Optional epilog, including comments, Processing Instruction (PI), and/or spaces following the elements.

8.1.4 Element

An element is a basic component of an XML tag.

Elements are separated by tags: Angle brackets enclose element type names. Each element must be separated by a start tag and an end tag.

Empty element <WebService> </WebService>
Instead of providing a package container, an empty element can be expressed as a thumbnail, indicating a mixture of start and end labels.
<WebService/>

Document element. Each document has only one root node, which is called the document entity or document root. Their root is called the document element ).

Elements of the XML pair must be correctly nested.

If a string contains single quotes, the separator must use double quotation marks, and vice versa.

8.1.5 character data

Character data is any text that is not marked. characters smaller than signs, greater than signs, and greater than signs are marked separators. Therefore, they must not appear in character data in the form of strings (except for the CDATA part ), the Escape Character "& It;" must be used.

8.1.6 attributes

An element is a noun in XML, and its attribute is its adjective.

Attribute name = "attribute alue"
Attribute name = 'attribute alue'

Only one instance can exist in the starting or empty tag.
Invalid:

In XML data, only four characters can be used as blank spaces, 09 horizontal indicator (HT), 0D carriage return (CR), 0A line feed (CF), and 20 spaces.

8.1.7 notes

<! -- Comment text -->

8.1.8 CDATA section

Is a method used to contain text. It is most useful for authors who want to include XML tags in their own documents.

When using these parts, almost all of the advantages of XML are lost.

<! [DATA [...]>, "..." can be any string, as long as it does not contain the string "]> ".

8.1.9 formal documents

The only direct relationship between elements is the parent-child relationship;
The sibling relationship is inferred from the data structure, which is neither direct nor reliable, because an element may be inserted between an element and one or more of its child elements.

If the data object meets the following requirements, it is a formal document of each city.

1. The syntax complies with XML specifications.

2. elements constitute a hierarchy tree with only one root node.

3. No reference to external entities unless a DTD is provided.

If any XML Parser discovers that it is not a regular structure, it will report a "Fatal" error. a fatal error may not necessarily cause the parser to terminate the operation, but it will no longer pass character data and/or XML structure to the application in a normal way.

8.2 XML namespace

8.2.1 namespace

The XML namespace is a solution to resolve multiple semantic and name conflicts.

A namespace is a set of structured names.

8.2.2 define and declare a namespace

The namespace Recommendation Standard provides the xmlns attribute, and the attribute value is URI.

The namespace prefix is often referred to as the prefix, and the name itself is the basic name.

Default namespace (the alias is not declared in the form of xmlns = "... "), in the declared scope, all names without the namespace prefix are assumed to belong to the default namespace.

8.3 DTD

If an XML document is valid, it must meet the following requirements: The document is associated with the document type.

8.3.1 What is a DTD

DTD document type definition.

It is mainly used to view the format of the XML document. In the preface of the XML document, the DTD declaration is not mandatory.

The DTD mainly defines the following aspects:

1. Element declaration.
2. Object declaration.
3. Attribute types.

8.3.2 why DTD is introduced

Providing a verification method is a major contribution to XML, ensuring that the XML file does comply with the specified format, which may be a standard, or a data exchange agreement jointly developed by both parties.

The file format is unified, improving the reusability of the file.

Using DTD for verification increases the operation time.

8.3.3 DTD Declaration

.

8.3.4 element Declaration

.

8.3.5 object Declaration

An entity is a pre-defined data.

Storage location, internal entity, external entity;
Content, which can be decomposed into entities and cannot be decomposed into entities.
Reference Method: generic Entity, parameter entity.

The object declarations and usage of different types are slightly different.

.

8.3.6 attribute Declaration

In the XML document, attributes only need to meet the naming rules. However, in a valid XML document, attributes must be declared by the DTD attribute.

In the DTD declaration, the attribute declaration syntax can be summarized as follows:

<! ATTLIST element name attribute type attribute default type>

The element name refers to the name of the element to which the attribute belongs.

8.4 XML Schema

Although the DTD is simplified, it is still a language with a completely different style from XML. The schema document is a special XML document that is easy to learn and use.

Another disadvantage of DTD is that the data type is quite limited. Data types are not provided at all in the DTD.

A single XML document can only use one DTD document, while a schema adopts the namespace mechanism, so that an XML document can call multiple schema documents.

8.4.1 logical XML Schema document structure

.

8.4.2 Element Definition

.

8.5 extensible style sheet language

(EXtensible Stylesheet Language, XSL) is a Language used to describe the style information of XML documents. It is developed by W3C.

One advantage of XML is that the form and content are separated. XSL is one of its two style forms,

CSS is a static style description format, which does not comply with XML syntax.

XSL is an XML document.

Is a specific application of XML.

It consists of two parts:

The first section describes how to convert an XML document into a readable or output format;

The second part defines how to convert the source tree of a format Object (Fomatted Object, FO) to a result tree that can be displayed. It is called a tree conversion. According to the result tree of the FO analysis, an output result is generated, this process is called formatting.

The transformation tree has become increasingly mature and has been separated from XSL. The other name is XSLT (XSL Transformations). Currently, most of the commonly heard XSL refers to XSLT.

Supporting standard Xpath (XML Path Language, XML Path Language)

Declare the XSL style sheet in XML:

<? Xml-styleshee type = "text/xsl" href = "mystyle. xsl"?>

XSL applications in the network are generally divided into two modes:

1. server-side Conversion Mode

Before downloading an XML file to a browser, convert it to HTML.

1. In dynamic mode, real-time conversion is performed when a conversion request is received.

2. batch mode.

2. Client Conversion Mode

Both XML and XSL files are transmitted to the client. The browser must support XML + XSL.

8.5.2 common syntax and functions of XSLT

.

8.6 other relevant regulations

8.6.1 XPath

Uses concise and non-XML syntax to navigate the structure based on the logical structure of the XML document.

XPath expressions usually appear in URL and XML Attribute values.

XPath depicts an XML document as a tree or node model, there are seven types of nodes: root node, element node, attribute node, text node, comment node, namespace node, and processing command node.

The XPath Specification defines two main parts: expression syntax and basic functions called the XPath core library.

The path pointing to a specific node in an XML document consists of three parts: an axis type, a node test, and a predicate.

There are multiple types of axes, specifying the relationship between the selected node and the environment. Test the types of nodes to be searched. The test includes the wildcards "*", text (), node (), comment (), and processing-instruction.

The predicate starts with "[" and ends with "]". The predicate uses internal functions to filter unnecessary nodes.

<Axis >:: <node test> [<predicate expression>]

8.6.2 XLink and XPointer

XLink specifies how a document is connected to another document. XPointer specifies the internal location of the document based on the XPath Recommendation Standard.

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.