Jump to content

XML Attribute vs Element


jcanker

Recommended Posts

Maybe it's a complete noob questions, but beyond XHTML and the notion that HTML should be valid XML, I don't see the benefit of using attributes instead of creating an element for that data.  One of the tutorials I read (tizag's) used a lemonade stand as an example, and they did:

<inventory>
<drink>
	<lemonade supplier="mother" id="1">
		<price>$2.50</price>
		<amount>20</amount>
	</lemonade>
	<pop supplier="store" id="2">
		<price>$1.50</price>
		<amount>10</amount>
	</pop>
</drink>

<snack>
	<chips supplier="store" id="3">
		<price>$4.50</price>
		<amount>60</amount>
		<calories>180</calories>
	</chips>
</snack>

</inventory>

 

But I just don't see the benefit of putting the supplier and ID as an attribute instead of as child elements of the specific snack.  It seems to me that placing them as child elements would make the XML more self-describing and therefore easier to parse and manipulate. 

 

Am I just missing something?  Why use attributes for anything other than making your HTML valid XHTML as is the current standard?  Why use attributes for XML in, say, data passed for an AJAX app?

Link to comment
https://forums.phpfreaks.com/topic/229782-xml-attribute-vs-element/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.