Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.