jcanker Posted March 6, 2011 Share Posted March 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/229782-xml-attribute-vs-element/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.