XML is similar to HTML. XML is a markup language. At the beginning, XML was designed not to drive HTML off the altar. In fact, XML was designed for another purpose. XML is used to transmit information. HTML is used to display information. HTML can contain tags, but cannot contain tags such as... XML and HTML.
First, XML is similar to HTML and is a markup language.
At the beginning, XML was designed not to drive HTML off the altar. In fact, XML was designed for another purpose.
XML is designed to transmit information, HTML is designed to display information
HTML can have any or no tags. they are restricted by a series of rules # code/12132.html "target =" _ blank ">;
However, in XML, you can define your own labels.
What is the use of XML?
Because XML is in plain text format, it is a real cross-platform data transmission format independent of any hardware and software.
Based on XML, many other technologies have also been developed. for example, the most familiar web service, the WSDL mechanism is implemented based on XML (also implemented based on JSON ).
This is because XML is a highly scalable data transmission format.
Syntax rules
The tag must be disabled.
For example, & lta> must have a matched pair. of course, & lta name = ""/> is a simple abbreviation.
Case Sensitive
XML documents must have root elements
The attribute value must be enclosed in quotation marks.
Escape of special characters
< - <> - >& - &' - '" - "
Note
Element 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.
Attribute
The attribute must be enclosed by quotation marks. if the attribute itself has double quotation marks, it will be enclosed by single quotation marks.
XML verification
There are many ways to verify whether the XML format is good. There are two common types:
XML DTD
Valid XML documents are "well-formed" XML documents, which also comply with the syntax rules of Document Type Definition (DTD:
George
John
Reminder
Don't forget the meeting!
In the preceding example, the DOCTYPE declaration references the external DTD file. The following section shows the content of this file.
]>
XML Schema
W3C supports an XML-based DTD replacement named XML Schema:
XML namespace
The main purpose of a namespace is to solve the problem of element naming conflicts. The following two XML configuration files have naming conflicts:
African Coffee Table
80
120
After namespace is used to resolve the conflict:
African Coffee Table
80
120
The attribute value of the xmlns in a namespace does not have much meaning. it is only used to distinguish the differences between namespaces. In fact, xmlns is used by developers to identify certain resources.
XML CDATA
The text in all XML documents will be parsed by the parser.
Only the text in the CDATA section is ignored by the parser.
PCDATA
PCDATA indicatesResolved character data(Parsed Character Data ).
The XML parser parses all the text in the XML document.
When an XML element is parsed, the text between tags is also parsed:
This article will also be parsed
The parser does this because the XML element can contain other elements, as in this example The element contains two other elements (first and last ):
Bill
Gates
The parser will break it into sub-elements like this:
Bill
Gates
CDATA
The term CDATA refers to text Data that should not be parsed by the XML parser (Unparsed Character Data ).
"<" And "&" are invalid in XML elements.
"<" Produces an error because the parser interprets the character as the beginning of the new element.
"&" Also produces errors because the parser interprets the character as the beginning of the character entity.
Some text, such as JavaScript code, contains a large number of "<" or "&" characters. To avoid errors, you can define the script code as CDATA.
All content in the CDATA section is ignored by the parser.
CDATA""</strong> 开始,由 <strong>""End:
《script》function matchwo(a,b){if (a < b && a < 0) then { return 1; }else { return 0; }}《script》
In the preceding example, the parser ignores all content in the CDATA section.
Comments about CDATA:
CDATA cannot contain strings "]> ". The nested CDATA section is not allowed.
"]>" Ending with CDATA cannot contain spaces or lines.
The above is the detailed introduction of XML, which is followed by Web programmers. For more information, see other related articles in the first PHP community!