Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

which one is a "better XML"

Status
Not open for further replies.

simul

Programmer
Nov 24, 2004
1
US
I have XML content to tranform to WML/XHTML etc.
Which of the following is "better" XML for representing links in the content

<link>
<text> search </text>
<method> post </method>
<posttofile> search.php </posttofile>
</link>

OR

<link method="post" posttofile="search.php">
search
</link>
 
It's a style question, and as such has no correct answer.

My personal preference is that only values which are about the data in the element belong in an attribue. An example would be a currency code:
Code:
<Salary CurrencyType="USD">35000.00</Salary>
Values which are not about the value in the element should not be in an attribute, an example of which are the country dialing prefix and the area & number values below. However, the type of phone would be a good candidate for an attribute:
Code:
<Phone PhoneType="Home">
   <CountryDialingCode>1</CountryDialingCode>
   <AreaCode>919</AreaCode>
   <Number>5551212</Number>
   <Extension />
</Phone>
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Although this isn't an issue with the example you presented, you might also want to consider how your parser treats attributes vs. tag content as a practical matter.

By definition, attributes are strings (always quoted.) The parser I use takes that as gospel: an attribute is always parsed as a string; if you want something different, it's up to you to perform a conversion. In contrast, the same parser will do its best to infer a datatype for content data: numeric data, for instance, is automatically correctly typed upon assignment.
 
harebrain is correct - if strong datatyping is necessary in your XML (as enforced by an XSD or other such device), you'll probably want to minimize the use of attributes.

If I recall correctly, attributes also handle the special XML character entities in an odd fashion -- the ampersand, less-than, greater-than, single-quote, and double-quote characters.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top