XML introduction, xml
Chapter 1 What is xml
Data Files in computers are classified into binary files and text files.
A binary file is a bit stream (1 or 0 series). Only the application that creates the binary file can understand the actual meaning of the bit stream.
Text files are also bit streams. The bit streams in text files are organized in a standard format. Therefore, they are always composed of numbers, and each number is mapped as a character.
A Brief History of Markup Language
Explore a way to exchange data between different computer programs. The earliest markup language is SGML. ==> and then HTML appears.
XML is a subset of SGML. XML is fully compatible with SGML.
For the same data, XML documents are much larger than plain text files. Marking Data with XML increases the size of the file, which is huge. generating small files is not the goal of xml. Its only goal is to structure the data, yes, developers can easily access data based on the data structure.
XML itself cannot perform any operations on the data. You must use a software called parser to import data. How the midpoint of XML represents data.
1.2 advantages of using XML
Easy to carry and transfer. XML is not dependent on special software, easy to share and cross-platform. xml itself is a text file and structured data, which can be easily read by various systems. The XML tree structure is easy to query.
1.3XML syntax
Each start tag must have an end tag.
An xml document can have only one root element.
Xml elements must be correctly nested
The attribute value must be enclosed in quotation marks.
An element cannot have the same attributes.
----------------------
Xml elements are the basic unit of xml documents.
The content between the start and end tags is called the content of an xml element. For example, woyouxian is the content of the element <site> woyouxian </site>.
If the xml element has no content, it is called an empty element. Empty elements have a special syntax, such as <site/>
Xml documents are case sensitive. The xml document is a tree structure with only one root element. Other elements are the descendant of the root element.
The relationships between xml elements are: child nodes, parent nodes, and parallel nodes, also known as sibling nodes.
Generally, xml attributes use double quotation marks or single quotation marks. If the attribute value contains double quotation marks, single quotation marks are used. If the attribute value contains single quotes, double quotation marks are used.
Xml does not specify which data should use elements or attributes. Both statements are correct.
Generally, attributes should be used for metadata (data describing data), and elements should be used for data.
1.3xml naming rules
It cannot start with a number or punctuation
Cannot begin with xml
Xml name cannot contain spaces
Cannot start with xml. Full stop. Colon. This is a reserved symbol of the xml namespace.
Xml entity reference
In XML, there are 5 predefined entity references:
Note: In XML, only the characters "<" and "&" are indeed invalid. It is a good habit to replace it with Entity references.
If the document you want to enter contains a lot of characters "<" or "&", it is very troublesome to replace all the characters. You can use the CDATA partition (CDATAsection ). In this region, the xml parser does not parse content in CDATA.
CDATA zone with <! [CDATA [start, end with]>
Note: it cannot appear in the CDATA area]>.
Xml comment to <! -- Starts and ends with -->.
XML Declaration
The xml document should start with an xml Declaration, but it is not required. To write a statement, it must be placed in the first line.
The xml Document declaration has three parameters:
Version)
The version indicates that the W3C xml1.0 standard is followed.
Encoding)
Character encoding indicates the encoding of the Characters Used by the xml document. Some xml documents in English documents, you will see that they use the hi single-byte ISO-8859-1 encoding, but for Chinese documents, should use dual-byte UTF-8 or Unicode
If it is an xml document that contains non-English characters, you will learn to associate the xml document with the village committee UTF-8 or Unicode ()
Standalone)
If the value of xml standalone is no, it requires a DTD.
The standalone value should be set to yes if you do not need a DTD xml document.
Xml namespace
The original purpose of the xml namespace standard is to solve naming conflicts in xml documents. Since the names in xml are predefined, conflicts may occur when the same element name is used in two different documents.
By adding a (URL) Location Method to the identity name,
The namespace is declared on the element using the xmlns attribute. The value of this attribute is the URL that identifies the namespace .... namespace Syntax: xmlns: <name >=< "uri">. NAME indicates the namespace prefix, and uri indicates the string of the namespace URi.
Once the prefix is declared, elements and attributes in the xml document can be limited and associated with the URI of the sensitive space.
<mybook:BOOK xmlns:mybook="http:........"><bb:BOOK xmlns:bb="urn:blue....">
If the Publisher element exists in the document and the namespace has been declared for the element, the Pbulisher element needs to add the namespace alias to the element with a colon,
If you want to declare and use the default namespace, omit aliases and semicolons from the element declaration.
<BOOK xmlns="http:......">
Any element that does not have a fully qualified namespace prefix belongs to the default namespace. The default namespace is only applicable to elements and does not apply to attributes. The namespace Declaration has a range, and the namespace is valid only within the corresponding range. There are two kinds of scopes: the default range and the limited range.
The default namespace is the namespace declared in the root element. It applies to all unlimited' elements in the document.
Specify that the namespace is declared when a more specific namespace is overwritten at a certain position in the document.
The namespace can be used only after being declared, but it is not necessarily at the beginning of the document.
1.4DTD and XML Schema
Document Type Definition (DTD) is a set of syntax rules for tags. It is a part of xml1.0, a validation mechanism for xml files, and is part of a file.
DTD is an effective method to ensure that the xml document format is correct.
DTD documents include: Definition rules of elements, definition rules of the relationship between elements, available attributes of elements, available entities or symbol rules,
The xml document provides an application data exchange format, and the DTD is exactly the standard that allows XML files to be called data exchange, because different companies only need to define standard DTD, companies can establish and verify xml files according to the DTD, so that they can easily establish standards and exchange data, thus meeting the needs of network sharing and
Data interaction.
DTD is an ASCII text file suffixed with. dtd. Each xml document can carry a DTD to describe the format of the document. Test whether this document is a valid xml document.
Xml Schema has become the w3c standard for recommendation, and there is a tendency to replace xml DTD. The xml Schema function is similar to the DTD function, but it is an xml document. It conforms to the xml syntax structure and can be parsed by the xml parser.
Xml Schema is like the table definition in the database, and the xml associated with this xml Schema is like the data in the database. It must meet the rules defined by the table,
1.5 Parse xml documents
Xml cannot do anything except store information. You need to process xml data. The software used to process xml documents is called a parser. The xml Parser allows you to read and write xml documents.
It depends on how they process xml documents. In the program, there are two types of xml files: stream model and DOM model (Document Object Model ).
There are two kinds of arguments in the stream model: the PUSH model and the PULL model. The PUSH model is commonly referred to as the SAX (simple xml api). The SAX is an event-driven model.
1DOM
2SAX
1.6XPath Introduction
Xml is a technology derived from xml. It is used to quickly search and query xml documents. xpa is the foundation of XSLT technology. It supports cross-platform and XPath comprehension. You can refer to the FilePath () in the directory structure ()
1.7XSLT Introduction
Is a language that converts xml to other text documents. Is an international standard based on xml and xpath.