Describes in detail how to learn attributes in XML.

Source: Internet
Author: User
Tags xml attribute
This article mainly introduces the attribute learning tutorial in XML, including examples of using attributes to store data in sub-elements. if you need it, refer to the following article to introduce the attribute learning tutorial in XML, examples of storing data in sub-elements using attributes are provided. For more information, see

Attributes are part of XML elements. An element can have multiple unique attributes. Attribute provides more information about XML elements. More accurately, they define the attributes of elements ). The XML attribute is always a _ name-value _ pair.

Syntax
The XML property syntax is as follows:

 
  ....content..   
 

Attribute1 and attribute2 have the following forms:

name = "value"

The value must be enclosed in double quotation marks ("") or single quotation marks. Attribute1 and attribute2 are both unique attribute tags.

Attribute is used to add a unique tag and classification tag to an element, add a Boolean attribute, or associate string data. The following example shows how to use attributes:

     
     
 ]>
 
  
  
 

Attribute is used to distinguish elements with the same name. When we do not want to create a new element for each scenario. We can use attributes to add more details to distinguish two or more similar elements.

In the preceding example, we classify plants by including the category attribute and assign different values to each element. Therefore, we have two plants categories: flowers and color. In this way, we get two plants elements with different attributes.

You can also see that this attribute is defined at the beginning of XML.

Attribute type
The following table lists the attribute types:

Attribute type Description
StringType Accept the string value as the value. CDATA is a StringType. CDATA is also character data. This also means that any non-tagcharacters are valid attributes.
TokenizedType

This is a restriction type. The Validity constraint specified in the syntax will be applied after the attribute value is normalized. The following is the TokenizedType attribute:

  • ID:Used to specify that the element is unique.

  • IDREF:It is used to reference an ID, which naming another element.

  • IDREFS:Used to reference all IDs of an element.

  • ENTITY:Indicates an external entity in the document.

  • ENTITYS:Indicates an external entity in the document.

  • NMTOKEN:It is similar to limiting which data can be a part of the CDATA attribute.

  • NMTOKENS:It is similar to limiting which data can be a part of the CDATA attribute.

EnumeratedType

Contains a predefined value list in its declaration. Here, it must be assigned a value. There are two types of enumeration attributes:

  • NotationType:It declares that the element will be referenced as a NOTATION declaration in some parts of the XML document.

  • Enumeration:Enumeration allows us to define a specific value list. the attribute value must match.


Element Property Rules
The following are the rules for defining attributes:

Attribute names in the same start tag or empty element tag can only appear once.
Attributes must be defined in Document Type Definition (DTD) using Attribute-List Declaration.
Attribute values cannot directly or indirectly reference external entities.
The alternative text of any entity directly or indirectly mentioned in the property value cannot contain signs (<).

Store data in sub-elements
The date attribute is used in one case:

 
  
   Tove
  
  
   Jani
  
  
   Reminder
  Don't forget me this weekend!
 

The second case uses the date element:

 
  
   12/11/2002
  
  
   Tove
  
  
   Jani
  
  
   Reminder
  Don't forget me this weekend!
 

The third case uses the extended date element (which is a common method ):

 
    
   
    12
     
   
    11
     
   
    2002
   
  
  
   Tove
  
  
   Jani
  
  
   Reminder
  Don't forget me this weekend!
 

The above is a detailed description of the property learning method in XML. For more information, see other related articles in the first PHP community!

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.