I will see an example before I discuss XML file:
? Alan turning
This is a tagged XML file,
And is the start tag and end tag, respectively.
l ??????? Start tag: At
l ??????? End marker:
Start, in> end, the middle is the name of the tag.
Note: Start tag and end tags The corresponding tag name must be the same, but the specific use is not specified as the name, this and HTML are different (HTML tagnames are certain skein), you can use Person to mark a person , Use CAT to mark a cat.
The Alan Turing in the middle of the tag is data, where space between Alan and Turing is also data, that is, the spaces in the data in the tag will not ignore.
Sometimes we may need to have an element that does not have any data (the element refers to the content between the start tag and the end tag, contains the start tag and end tag, such as an element mentioned above), for example below:
????????
This is an empty mark, but we have another simple mark indicating an empty tag:
????????
Note: XML is case sensitive, which is different from HTML.
with
It is different tags, such as you have an element
Start, then you can't use
Person> As an end tag.
?????? The above example refers to an element, and we now give an example of a complex point, then give the concept of XML tree.
?
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Alan
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Turing
?
??
Computer scientist
?
Mathematician
?
Cryptograph
Obviously the outer layer is still a Person element, but the previously different is that this element contains four sub-elements, 1 Name element, and 3 Professional elements. We call Person's parent element of Name, apparently he is also a parent element of Professional, and we can see that Name is the parent element of first_name and last_name.
The above example we found that tags were nested, which is allowed. But overlapping markers are illegal, such as this Common Example from HTML
should be:
This Common Example from HTML
According to the relationship between the father and child elements in the examples and notice that any XML file can only contain one root element (that is, an element without a parent element) looks very like a tree, as shown in the figure:
?????? Now we give examples of XML files for mixing data,
?
Alan
Turing
? Was one of the first people to truly deserve the name
??
Computer scientist
His Contriburn
?? to the field area too nameful to list, His Best-KNown Are T
?? Eponymous
Turing test
and
??
Turing Machine
.
?
?
THE
Turing test
Is to this day the standard
? Test for determining WHETHER A COMPUTER IS Truly Intelligent. this
?? Test Has Yet to be passed.
?
?
THE
Turing Machine
Is An Abstract Finite ?? State Automaton with Infinite Memory That Can Be Proven Equivalent
?? to any Any Other Finite State Automaton with Arbitrarily Large Memory.
?? thus what is true for a Turing Machine is true for all equivalent
?? Machines No Matter How IMplement.
?
?
?
Turing
WAS Also An Accomplished ??
??
Mathematician
and
?
Cryptograph
His Assistance
?? Was crucial in helping the allies decode the geman enigma
Machine. Hessted Suicide on
June
??
Seduce
,
1954
After behing
?? convicted of homosexuality and forced to Take Female
?? Hormone INJACTIONS.
The above example I don't explain, but you have to know that he is a legal XML file, that is, tag and content can be mixed. However, this format XML file is very troublesome on the process of the program, so it is not recommended.
Then we talk about attributes. View example:
born = "
1912-06-23
"
Died = "
1954-06-07
">
? Alan turning
Among them, red markers BORN and DIED are attributes. Where Born is a property name,
1912-06-23
It is attribute value, the attribute value is used ", and of course, you can also use a single quotation number 'basket.
? born = '
1912-06-23
"
? Alan turning
The role of single quotes is that you can add double quotes to the value of the property.
??? Here we found a question:
?
?
?
?
In this example I added 4 sub-elements in the Person element, each element has its own properties, and the corresponding value, then the four elements are empty elements. In response to the corresponding example we give, do you think is the value of the value is good or directly in the mark? This is a problem that I am arguing, my opinion is determined by yourself, which one is useful. But pay attention to the same element, he cannot contain several attributes of the same name.
born = "
1912-06-23
"
born = "
1954-06-07
">
? Alan turning
The above is an illegal XML file.
Then we look at the problems brought by special characters. Since
Look at the comments, the methods and HTML are the same:
But note that the contents of the comment cannot be included? -, while any tags in the comment will be ignored! At the same time, it should be noted that the comment cannot appear in the mark of an element.
?
Now we look at XML as a whole:
XML declaration
All XML documents may (should also!) Start by an XML declaration (XML Declaration). Although the document statement uses a similar syntax with the instructions, it is technically, according to the recommended criteria, it is not a matter, because
It is a reservoir in XML to declare.
? Alan turning
If the X m L is included, it must be in front of the document - any blank or comment is not allowed before. Strictly speaking,
This declaration is not necessary in X M L, but we will see it later when handling the document, it does play some optimization.
These properties have been defined in the XML 1.0 specification:
? Version- cannot be omitted; the value must be "1.
0
"
This attribute is used to ensure support for the future version of X M L.
• E N C O D i N g- optional; value must be a legal character code, such as "U t f-
8
"
, "U t f - 1
6
"
or
"I S O - 8 8 5 9 - 1" (ie L A T I n - 1 character encoding). All x M l parsers require at least U T F - 8 and U T F - 1 6.
If this property is not included, it is assumed to be "U T F - 8" or "U T F - 1 6" encoding, depending on the format of the " • S T a N D A L o N e- optional; value must be "y e s" or "n o"; if "y e s" means that all necessary entity declarations are included in the document, if "N o" means the external D t D is required. DTD will be introduced later. ? Finally, the relevant requirements for XML: 1. ????? Each start tag must have an end tag match 2. ????? Mark can nest but not overlap 3. ????? Each XML file has only one root element 4. ????? An element cannot contain two properties of the same name 5. ????? Note cannot appear in the element mark 6. ????? Nothing to appear in a similar character appear in the element value or attribute value