XMLThe document contains XML elements.
What is an XML element?
The XML element refers to the part from (and including) the start tag to (and including) the end tag. The
element can contain other elements, text, or a mixture of both. Elements can also have attributes.
<bookstore> <book category="CHILDREN"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title>LearningXML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
In the above example,
In the above example, only the
XML naming rules
XML elements must follow the following naming rules:
The name can contain letters, numbers and other characters. The name cannot start with numbers or punctuation marks. The name cannot start with The name starting with the characters "xml" (or XML, Xml) cannot contain spaces
Any name can be used, no reserved words.
Best Naming Practices
Make the name descriptive. It's also a good idea to use underscores in names.
The name should be short, such as:
Avoid the "-" character. If you name it like this: "first-name", some software will think you need to extract the first word.
Avoid the "." character. If you name it like this: "first.name", some software will think that "name" is a property of the object "first".
Avoid the ":" character. The colon will be converted to namespace for use (described later).
XML documents often have a corresponding database, whose fields correspond to elements in the XML document. A practical rule of thumb is to use the database's naming rules to name elements in an XML document.
Non-English letters such as éòá are also legal XML element names, but you need to be aware of problems that may arise when software developers do not support these characters.
XML elements are extensible
XML elements are extensible to carry more information.
Look at the following XML example:
<note> <to>George</to> <from>John</from> <body>Don't forget the meeting this weekend!</body> </note>
Let's imagine that we create an application that extracts the
MESSAGE To: George From: John Don't forget the meeting this weekend!
Imagine that the author of this XML document later adds some additional information to this document:
<note> <date>2008-08-08</date> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting this weekend!</body> </note>
Will the application break or crash? ?
Won't. This application can still find the
One of the advantages of XML is that it can often be extended without interrupting the application.
The above is the detailed content of XML development basics-XML elements. For more information, please follow other related articles on the PHP Chinese website!