tags:

views:

276

answers:

1

I have seen many programmers write XML in very different ways. One of the major differences I have seen is how attributes versus child nodes are used to represent data.

Scenario A:

A property of an element (say 'name') is represented using an attribute of that element node.

<JobTypes>
    <JobsType name="Job Type 1">
        <blah blah blah... />
    </JobType>
</JobTypes>

Scenario B:

A child node is used to represent all properties of the node.

<JobTypes>
    <JobType>
        <Name>Job Type 1</Name>
        <Value>Value 1</Value>
    </JobType>
</JobTypes>

QUESTION: What is the recommended pattern for XML attributes versus XML child nodes?

I'm assuming one convention is to keep properties that describe the XML document separate from the data model as attributes and real world data as child nodes. But if the XML is simple enough, wouldn't an attribute be valid as well? Does it even matter as long as it is done consistently?