


Detailed introduction to attribute learning methods in XML
This article mainly introduces the attribute learning tutorial in XML, including examples of using attributes to store data in sub-elements. Friends in need can refer to it
Attributes are part of XML elements. An element can have multiple unique attributes. Attributes provide more information about an XML element. More precisely, they define the element's properties. An XML attribute is always a name-value pair.
Syntax
The XML attribute syntax is as follows:
<element-name attribute1 attribute2 > ....content.. </element-name>
where attribute1 and attribute2 have the following form:
name = "value"
value must be wrapped in double quotes (" ") or single quotes (' '). Here attribute1 and attribute2 are both unique attribute labels.
Attributes are used to add a unique label to an element, a category label, add a Boolean attribute or associate some string data. The following example demonstrates how to use attributes:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE garden [ <!ELEMENT garden (plants)*> <!ELEMENT plants (#PCDATA)> <!ATTLIST plants category CDATA #REQUIRED> ]> <garden> <plants category="flowers" /> <plants category="shrubs"> </plants> </garden>
Attributes are used to distinguish elements with the same name. When we don't want to create a new element for every case. We can use attributes to add more detail to differentiate between two or more similar elements.
In the above example, we have classified the plants by including the category attribute and assigned a different value to each element. So we have two plants categories, one is flowers and the other is color. This way we both get two plants elements with different attributes.
You can also see that we define this attribute at the beginning of the XML.
Attribute Type
The following table lists the attribute types:
Attribute Type | Description |
---|---|
StringType | Accepts a string value as the value. CDATA is a StringType. CDATA is also character data. This also means that any non-markup character is a legal attribute. |
TokenizedType | This is a restricted type. Validity constraints indicated in the grammar are applied after attribute values are normalized. The following is the TokenizedType attribute:
|
EnumeratedType | Contains a predefined list of values in its declaration. Here it must be assigned a value. There are two types of enumeration attributes:
|
Element attribute rules
The following are the rules to follow when defining attributes:
The attribute name can only appear once in the same start tag or empty element tag.
Attributes must be defined in the document type definition (DTD) using the Attribute-List Declaration.
Attribute values cannot directly or indirectly reference external entities.
The alternative text of any entity mentioned directly or indirectly in the attribute value cannot contain a less than sign (<).
Storing data in child elements
The date attribute is used in one case:
<note date="12/11/2002"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
It is used in the second case Date element:
<note> <date>12/11/2002</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
The extended date element is used in the third case (this is our common method):
<note> <date> <day>12</day> <month>11</month> <year>2002</year> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
The above is the detailed content of Detailed introduction to attribute learning methods in XML. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

How to handle XML and JSON data formats in C# development requires specific code examples. In modern software development, XML and JSON are two widely used data formats. XML (Extensible Markup Language) is a markup language used to store and transmit data, while JSON (JavaScript Object Notation) is a lightweight data exchange format. In C# development, we often need to process and operate XML and JSON data. This article will focus on how to use C# to process these two data formats, and attach

Python's dir() function: View an object's properties and methods, specific code example required Summary: Python is a powerful and flexible programming language, and its built-in functions and tools provide developers with many convenient features. One of the very useful functions is the dir() function, which allows us to view the properties and methods of an object. This article will introduce the usage of the dir() function and demonstrate its functions and uses through specific code examples. Text: Python’s dir() function is a built-in function.

Jackson is a Java-based library that is useful for converting Java objects to JSON and JSON to Java objects. JacksonAPI is faster than other APIs, requires less memory area, and is suitable for large objects. We use the writeValueAsString() method of the XmlMapper class to convert the POJO to XML format, and the corresponding POJO instance needs to be passed as a parameter to this method. Syntax publicStringwriteValueAsString(Objectvalue)throwsJsonProcessingExceptionExampleimp

Bottom attribute syntax and code examples in CSS In CSS, the bottom attribute is used to specify the distance between an element and the bottom of the container. It controls the position of an element relative to the bottom of its parent element. The syntax of the bottom attribute is as follows: element{bottom:value;} where element represents the element to which the style is to be applied, and value represents the bottom value to be set. value can be a specific length value, such as pixels

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

If you want to get the pixels to which the document is scrolled from the upper left corner of the window, use the pageXoffset and pageYoffset properties. Use pageXoffset for horizontal pixels. Example You can try running the following code to learn how to use the pageXOffset attribute in JavaScript - Live Demonstration<!DOCTYPEhtml><html> <head> <style> &

Thread of Despair is a rare card in Blizzard Entertainment's masterpiece "Hearthstone" and has a chance to be obtained in the "Wizbane's Workshop" card pack. Can consume 100/400 arcane dust points to synthesize the normal/gold version. Introduction to the attributes of Hearthstone's Thread of Despair: It can be obtained in Wizbane's workshop card pack with a chance, or it can also be synthesized through arcane dust. Rarity: Rare Type: Spell Class: Death Knight Mana: 1 Effect: Gives all minions a Deathrattle: Deals 1 damage to all minions
