XML: Attributes vs. Children

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
RobertPaul
Forum Contributor
Posts: 122
Joined: Sun Sep 18, 2005 8:54 pm
Location: OCNY

XML: Attributes vs. Children

Post by RobertPaul »

Is there any kind of rule (or general "best practice") regarding the use of attributes vs. children to define values? Just for example:

Code: Select all

<dog>
	<name>Fido</name>
	<color>Black</color>
	<size>Toy</size>
</dog>
vs.

Code: Select all

<dog name="Fido" color="Black" size="Toy" />
Is one "better" than the other?
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

Post by vietboy505 »

I like children rule better.

XML look much nicer.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I seriously don't have a very good answer for you, but I think it does look better aesthetically. It seems much easier to interpret, although I'm not sure on the differences when having to parse the xml file considering I've worked little with xml..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from a regex point of view, children is easier to parse :P and I believe it's a bit more object oriented too.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Children seems more logical, and more scalable.

Mac OSX uses XML with children for all it's kext and config files ;)
Post Reply