Main > Everything Else
XML formatting
Dartful Dodger:
I’ve been writing my xml pages like this:
<item>
<name>
sprocket
</name>
<image>
sprocket.jpg
</image>
<info>
It's a sprocket
</info>
</item>
But a client gave me an xml page that looks like this:
<item name="sprocket" image="sprocket.jpg" info="It's a sprocket" />
For future projects that are started by me, should I use this formatting?
To me it’s 6 and half a dozen. I write it the first way because people are idiots so I wanted it to be as simple and bug free for them to edit as possible.
The second one looks easier to read but also looks like a ton of dumb-butt tech support calls waiting to happen. Putting strings in quotes means they can’t use quotes in their strings without extra formatting on their part.
I've worked with an xml file that had a combination of both types, but that wasn't as clean to work with. Maybe I haven't given the combo formatting a fair shake.
How are you guys writing it? Am I over reacting to the potential client formatting errors?
RayB:
Well... that's the thing about XML. It's too flexible. Personally, in my own projects I use the 2nd example format as much as possible, because it reads way easier and involves less nodes to parse, and visually everything is "together".
HOWEVER! I think there are limits on how many characters you can have in an attribute. So for anything that's longer than a short sentence, I then resort to your first method.
But shouldn't your client be using " anyways?
SirPeale:
--- Quote from: RayB on July 25, 2008, 02:23:02 pm ---
But shouldn't your client be using " anyways?
--- End quote ---
It's been a while since I did this stuff, but isn't " for displaying a quotation mark, and actual quotation marks for constraint?
SavannahLion:
--- Quote from: Peale on July 25, 2008, 03:24:31 pm ---
--- Quote from: RayB on July 25, 2008, 02:23:02 pm ---
But shouldn't your client be using " anyways?
--- End quote ---
It's been a while since I did this stuff, but isn't " for displaying a quotation mark, and actual quotation marks for constraint?
--- End quote ---
Correct. However, I don't recall if " is valid within an attribute though. Never had the need to use " there.
boykster:
I prefer to use a mixed approach; for attributes that are 1:1 and directly relate to the parent node, I use an inline notation (second example above). For anything that could be consider a 1 : many relationship, or considered a child element, rather than an attribute, I use a nested element (first example above). Of note, nested elements can have their own attributes.
Taken from http://en.wikipedia.org/wiki/XML#Well-formed_documents:_XML_syntax
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="8" unit="dL">Flour</ingredient>
<ingredient amount="10" unit="grams">Yeast</ingredient>
<ingredient amount="4" unit="dL" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
</instructions>
</recipe>
One reason I take this approach is that it maps well to a relational table structure.
Navigation
[0] Message Index
[#] Next page
Go to full version