Intimate contact with XML (6)-content of elements

Source: Internet
Author: User
Xml


element has a different content type. An XML element is everything from the beginning of the (containing) element to the end tag of the (containing) element.
An element can have element content, mixed content, simple content, and empty content. An element can also have attributes. In the example above, the book has element content because it contains other elements. Chapter has mixed content because it contains text and other elements. Para has simple content (or text content) because it contains only text. Prod has empty content because it does not carry any information. In the above example, only the PROD element has attributes. The value of the property ID is "33-657". The value of the property media is "paper".

Name of the element

XML elements must follow the following naming conventions:

Names can contain letters, numbers, and other letters.
Names cannot begin with numbers or "_" (underscores)
Names cannot begin with the letter XML (or XML or XML ...).
The name cannot contain spaces
Be aware that when you "invent" an element name, observe the following simple rules:

Any name can be used, and no word is reserved, but make sure that the name has a descriptive nature. A name with an underscore separator is fine.

For example: < First_name&gt, < last_name>.

To avoid using the "-" and "." In the name. Confusion occurs if your software wants to subtract name (first-name) or to use "name" as the property of object "a" (first.name).

You can make the element name as long as you like, but don't overdo it. Names should be short, such as < Book_title&gt, and preferably not:
< the_title_of_the_book>.

XML documents typically have a corresponding database with fields that correspond to elements in an XML document. It is best to apply the naming rules for elements in an XML document to the naming of the database.

Non-English letters such as Éòá are also legal in XML element names, but see if your software vendor supports them.

You cannot use ":" in an element name because it is reserved for something that becomes a "namespace" (namespaces). This will be covered later in this article.

XML attribute

As with HTML, an XML element can have attributes in its starting tag. property is used to provide additional information about the element.

XML attribute

XML elements can have attributes. In HTML only sense, you may remember: < IMG src= "Computer.gif" >. The SRC attribute provides some additional information about an IMG element. In HTML (and XML), properties provide additional information about an element:

< img src= "Computer.gif" >
< a href= "demo.asp" >

The information provided by a property is usually not part of the data. In the following example, the file type has nothing to do with the data, but it is important for the software that wants to manipulate the element:

< file type= "gif" >computer.gif</file>

Quote form, "female" or ' female '?

Property values must always be enclosed in quotation marks, but both single and double quotes are available. For a person's gender, a person's mark can be written like this:

< person sex= "female" >

Or write like this:

< person sex= ' female ' >

Double quotes are most commonly used, but sometimes (if the property value itself contains quotes), you must use single quotes, as in the following example:

< gangster name= ' George ' shotgun ' Ziegler ' >




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.