XML development basics-XML elements

黄舟
Release: 2017-03-25 17:04:25
Original
1632 people have browsed it

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>
Copy after login

In the above example, and both have element content because they contain other elements. has text content only because it contains only text.

In the above example, only the element has the attribute (category="CHILDREN").

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: , not: .

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&#39;t forget the meeting this weekend!</body>
</note>
Copy after login

Let's imagine that we create an application that extracts the , and elements out, and produces the following output:

MESSAGE
To: George
From: John
Don&#39;t forget the meeting this weekend!
Copy after login

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&#39;t forget the meeting this weekend!</body>
</note>
Copy after login

Will the application break or crash? ?

Won't. This application can still find the , , and elements in the XML document and produce the same output.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template