Trying to update a incident reporting web app we have here to save some files as XML. Now I know there is no correct answer generally with XML but wondered if anyone had pros or cons for two different structures. My original thought was to have each item as an element ending up with:
I know that will do it and is nice and simple to be readable straight from the file. A script I have found automagically can read from a form and create an XML file but creates this structure:Code:<?xml version="1.0" ?> <sis> <student></student> <date></date> <from></from> <tutor></tutor> <lm></lm> <house></house> <ha></ha> <ah></ah> <alt></alt> <prob></prob> <taken></taken> <needed></needed> </sis>
Now on some level that just doesn't sit right with me but if it works and is all good I can live with that.Code:<?xml version="1.0"?> <contact> <field id="student" taborder="1"> <field_value>A NAME</field_value> </field> <field id="date" taborder="2"> <field_value>02/02/2007</field_value> </field> <field id="from" taborder="3"> <field_value>INITIALS</field_value> </field> <field id="tutor" taborder="4"> <field_value>A ANOTHER NAME</field_value> </field> <field id="hoh" taborder="5"> <field_value>YET ANOTHER NAME</field_value> </field> <field id="house" taborder="6"> <field_value>A HOUSE</field_value> </field> <field id="learnAss" taborder="7"> <field_value>MORE NAME</field_value> </field> <field id="assHead" taborder="8"> <field_value>EVEN MORE NAME</field_value> </field> <field id="altLM" taborder="9"> <field_value></field_value> </field> <field id="attention" taborder="10"> <field_value>STAFF CODE</field_value> </field> <field id="problem" taborder="11"> <field_value>TEST TEST TEST</field_value> </field> <field id="actioned" taborder="12"> <field_value>TEST TEST TEST</field_value> </field> <field id="actionreq" taborder="13"> <field_value>NO TEST</field_value> </field> </contact>
Can anyone spot a major flaw or future issue with the second structure or a huge benefit for the first? Or am I just being picky, picky, picky?
Ta
I would personally go for the first one. Second one just defines everything as "field" and sets a tab order and id.

The second version looks as if it will make it more difficult when using XPath to get the infromation you need, and making the file size larger at the same time. But if the scripts you'll be using can read from the generated XML correctly, it shouldn't be a problem as long as it's all valid XML.
Ta. My spidey senses were correct. I'm sure I can hack the script to sort that out. It is a function script so probably made to service many forms, whereas mine will be to service one specific form so could be hard coded to just that.
Thansk again, means that XML stuff I learnt a while back actually may have sunk in!

Nice one
If you wanted to, you could use an XSLT stylesheet to transform version 2 into version 1 but why make things extra-complex :P
There are currently 1 users browsing this thread. (0 members and 1 guests)