xml attribute summary code details
Like HTML, XML elements can have element attributes at the beginning of the tag. Attributes usually contain some additional information about the element.
-------------------------------------------------- ------------------------------------
XML attributes
XML elements can Possess properties.
You must still remember this HTML code: . src is an attribute of the img element and provides additional information about the img element.
In HTML (and in XML as well) an element's attributes provide additional information about the element.
<img src="computer.gif"> <a href="demo.asp">
Letters provide information that is usually not part of the data. In the following example, the type has nothing to do with the data, but it is very important to the software that operates on this element.
<file type="gif">computer.gif</file>
--------------------------------------------- -------------------------------------
Citation style "female " Or 'female'?
The attribute value must be enclosed in quotation marks. Both single quotes and double quotes can be used. For example, the gender of a person, the person element can be written like this:
<person sex="female">
can also be written like this:
<person sex='female'>
There is no difference between the above two writing methods under normal circumstances. Use double Quotation marks are more commonly used. But in some special cases, single quotes must be used, such as the following example:
<gangster name='George "Shotgun" Ziegler'>
--------------------- -------------------------------------------------- ---------
Use child elements or attributes
Data can be stored in either child elements or attributes.
Please see the following example:
<person sex="female">Anna Smith female Anna Smith
In the first example, sex is an attribute, in the second example, sex is a child element. Both examples provide the same information.
There is no ready-made rule to follow when to use attributes and when to use subelements. My experience is that attributes can be quite convenient in HTML, but in XML you're better off avoiding them.
-------------------------------------------------- ------------------------------------
My favorite style
me Prefer to store data into child elements.
The following three XML documents contain the same information:
The first example uses the data attribute:
<note date="12/11/99"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
The second example uses the data element:
<note> <date>12/11/99</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
The third example uses the extended data element: (This is the style I recommend):
<note> <date> <day>12</day> <month>11</month> <year>99</year> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
----------------- -------------------------------------------------- -------------
Avoid using attributes?
Should we avoid using attributes?
Here are some problems caused by using attributes:
Attributes cannot contain multiple values (child elements can).
Attributes are not easy to extend.
Attributes cannot describe the structure (subelements can).
Attributes are difficult to handle by program code.
Attribute values are difficult to test via DTD.
If attributes are used to store data, the XML document written must be difficult to read and operate. Try to use elements to describe data, and only use attributes to describe additional information that has little to do with the data.
Don't do like the example below (if you do that, you haven't understood the above point).
<note day="12" month="11" year="99" to="Tove" from="Jani" heading="Reminder" body="Don't forget me this weekend!"> </note>
--------------------------------------------- -------------------------------------
Exceptions to attribute rules
There are always exceptions to rules.
There is an exception to my rules about attributes:
Sometimes you should designate an ID reference for an element, through which the specific XML element can be referenced and accessed, just like in HTML The name and id attributes are the same. Please look at the following example:
<messages> <note ID="501"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note ID="502"> <to>Jani</to> <from>Tove</from> <heading>Re: Reminder</heading> <body>I will not!</body> </note> </messages>
In the above example, the ID attribute is equivalent to a counter, or a unique identifier, which identifies different note information in the XML document. It is not a note information. part.
What we are trying to explain to readers is that metadata (data related to data) should be stored in the form of attributes, and the data itself should be stored in the form of elements.
The above is the detailed content of xml attribute summary code details. 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

AI Hentai Generator
Generate AI Hentai for free.

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
