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!

XML Newbie:Strutural Integrity

Status
Not open for further replies.

obiwasabi

Programmer
Nov 16, 2004
9
US
Hi,

In the following xml doc, which is meant as an exercise for XSLT Transformations, and later FLASH. I'm soliciting pointers on the well-formedness of the document. Also when one should use an attribute, instead of a new element.
<?xml version="1.0" encoding="iso-8859-1"?>
<employeeRecords>
<employee id="1">
<name>
<first>Mike</first>
<last>Watt</last>
</name>
<idNumber>7765</idNumber>
<position>Vice-President</position>
<sex>Male</sex>
</employee>
<employee id="2">
<name>
<first>Allison</first>
<last>Cole</last>
</name>
<idNumber>7225</idNumber>
<position>President</position>
<sex>Female</sex>
</employee>
<employee id="3">
<name>
<first>Albert</first>
<last>Filson</last>
</name>
<idNumber>7254</idNumber>
<position>Dock Supervisor</position>
<sex>Male</sex>
</employee>
<employee id="4">
<name>
<first>Denice</first>
<last>Clarke</last>
</name>
<idNumber>3636</idNumber>
<position>Administrative Assistant</position>
<sex>Female</sex>
</employee>
<employee id="5">
<name>
<first>Janet</first>
<last>Wood</last>
</name>
<idNumber>1889</idNumber>
<position>Sr. Vice President</position>
<sex>Female</sex>
</employee>
</employeeRecords>
 
Your document is well-formed, so no worries.

Regarding attributes vs. elements -- I use attributes when the attribute value pertains to the element, but needs to be stored separately. A good example would be currency codes -- you have a money value but need to indicate which currency it's in:
Code:
   <BankBalance currency="USD">5000.00</BankBalance>
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi,

Thanks For The Prompt Reply

So in my example file, really all of the additional information, after the name could be an attribute?


C
 
File is well-formed.
You can check by opening it in IE, though I'd say: get hold of an xml-editor: you'll need it when writing xsl. is OK, and it's freeware.

As for using attributes: people disagree, so let's say it's a matter of taste. In my opinion, attributes should only be used for meta-data, like:
<first_name updatable='True'>Jack</first_name>
But you'll also find:
<field name='first_name' value='Jack' updatable='True'>
any many variations.

The only thing I'd change in your xml is: remove the <name> node, it doesn't seem to add anything.
<first_name>Mike</first_name>
<last_name>Watt</last_name>
But that's also just a matter of taste, your file will work just as well for any purpose.
 
Hi Chip
;-)

Obiwasabi:
You could put all your info in attributes for just the <employee>-node, but it would be difficult to read, and you'll never be able to give one employee two positions (or a career).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top