Click to See Complete Forum and Search --> : Correct way of creating this XML


Lubox
08-23-2005, 09:21 AM
Hi

I'm going to create a little XML doc/string which external people are going to read and I'm wondering how I should structure it correctly. The XML is going to contain a list of customers and their collection of "keys". I was thinking something like this:

<CUSTOMERDATA>
<NAME>Elvis</NAME>
<KEY>
<OLDKEY>BLEPPBLUPP</OLDKEY>
<NEWKEY>KLABBBABB</NEWKEY>
</KEY>
<KEY>
<OLDKEY>NUNUNUNUNU</OLDKEY>
<NEWKEY>YEYEYEYE</NEWKEY>
</KEY>
</CUSTOMEDATA>
<CUSTOMERDATA>
<NAME>Presley</NAME>
<KEY>
<OLDKEY>KBABABABA</OLDKEY>
<NEWKEY>LEPEPEPE</NEWKEY>
</KEY>
<KEY>
<OLDKEY>LKJDLDJK</OLDKEY>
<NEWKEY>OIFUOFUOIF</NEWKEY>
</KEY>
</CUSTOMEDATA>

To make this correct XML, should I number the keys, like <KEY1>, <KEY2> etc? Should the CUSTOMERDATA also be numbered then?

Thanks
Lubox

sheila
08-23-2005, 03:59 PM
How about:

<customer @id="PER1">
<name><forename>Elvis</forename><surname>Presley</surname></name>
<key current="no">BLEPPBLUPP</key>
<key>KLABBBABB</key>
</customer>

But why do you want to keep a record of the old key anyway? If it's so that you have an historical record of the customer's keys then you could do it this way:

<customer @id="PER1">
<name><forename>Elvis</forename><surname>Presley</surname></name>
<key created="20050823T20:50:00">BLEPPBLUPP</key>
<key created="20050823T20:52:05">KLABBBABB</key>
</customer>

Assuming the key created most recently is the current key, you could sort them by key/@created to find out which it is.
Also, you don't need to name the keys <KEY1>, <KEY2> etc. as even if they are all called <KEY> you can still reference them as key 1 or key 2 using their position:

<xsl:variable name="key1" select="key[1]" />
<xsl:variable name="key2" select="key[2]" />