Build Your Own Arcade Controls Forum
Main => Everything Else => Topic started by: Dartful Dodger on July 25, 2008, 12:45:52 pm
-
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?
-
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?
-
But shouldn't your client be using " anyways?
It's been a while since I did this stuff, but isn't " for displaying a quotation mark, and actual quotation marks for constraint?
-
But shouldn't your client be using " anyways?
It's been a while since I did this stuff, but isn't " for displaying a quotation mark, and actual quotation marks for constraint?
Correct. However, I don't recall if " is valid within an attribute though. Never had the need to use " there.
-
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.
-
http://en.wikipedia.org/wiki/XML#Well-formed_documents:_XML_syntax
Useful link, thanks!
-
http://en.wikipedia.org/wiki/XML#Well-formed_documents:_XML_syntax
Useful link, thanks!
Agreed.
I've already been doing it one way and had to teach the non programmers/interns in the office how to write it that way. It was a pain and I didn't want to teach them a new way, but it looks like that's the best way to go about doing it.
I'll read over that link when I have more time so I can figure out the best way to program it. This way the next time I show them how I want it written will be the last.
I’m sure these lessons are as painful for them as they are for me.