Reputation: 846
I have a very basic question on XML design. I have XML which is used for generating UI. Its format is somewhat like below:
<Input>
<Label>Enter Machine Name</Label>
<ToolTip> Please enter the correct machine name</ToolTip>
<Type>TextField</Type>
</Input>
My question is whether writing the XML in above format is better or in the below format for better processing time results.
<Input Label="Enter Machine Name"
ToolTip="Please enter machine name"
Type="TextField">
Which type of XML will be parsed in lesser time?
Upvotes: 3
Views: 1351
Reputation: 111491
While attributes will take a bit less space, which is an advantage for performance, and a SAX parse will generate less events for the attribute-based design, which can save a minute amount of time, any attribute vs element performance difference is simply not going to matter in the vast majority of cases.
As with most a priori performance worries, it's better to build, measure, and adjust, provided your basic design is sound. The soundness of your basic design is not going to be driven by elements vs attributes.
You should try to use an industry standard schema for your XML and follow what they do regarding elements vs attributes. If you're designing on your own from scratch, see XML Element vs XML Attribute and the other sibling answers there.
Upvotes: 5
Reputation: 11855
You should use elements since it's data, see:
- XML best practices: attributes vs additional elements
- http://www.w3schools.com/dtd/dtd_el_vs_attr.asp
Elements and attributes are both common in XML, so expect that parsers are optimized to handle both well. I guess elements are found a bit faster, but I only looked at jQuery Sizzle results:
jQuery select by class VS select by attribute
Upvotes: -3