Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: XML formatting  (Read 1353 times)

0 Members and 1 Guest are viewing this topic.

Dartful Dodger

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3453
  • Last login:July 23, 2012, 11:21:39 pm
  • Newer isn't always better.
XML formatting
« 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?

RayB

  • I'm not wearing pants! HA!
  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 11279
  • Last login:July 10, 2025, 01:33:58 am
  • There's my post
    • RayB.com
Re: XML formatting
« Reply #1 on: July 25, 2008, 02:23:02 pm »
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 &quot; anyways?
NO MORE!!

SirPeale

  • Green Mountain Man
  • Global Moderator
  • Trade Count: (+23)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 12963
  • Last login:August 04, 2023, 09:51:57 am
  • Arcade Repair in New England
    • Arcade Game and Other Coin-Op Projects
Re: XML formatting
« Reply #2 on: July 25, 2008, 03:24:31 pm »

But shouldn't your client be using &quot; anyways?


It's been a while since I did this stuff, but isn't &quot; for displaying a quotation mark, and actual quotation marks for constraint?

SavannahLion

  • Wiki Contributor
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5986
  • Last login:December 19, 2015, 02:28:15 am
Re: XML formatting
« Reply #3 on: July 25, 2008, 03:35:42 pm »

But shouldn't your client be using &quot; anyways?


It's been a while since I did this stuff, but isn't &quot; for displaying a quotation mark, and actual quotation marks for constraint?

Correct. However, I don't recall if &quot; is valid within an attribute though. Never had the need to use &quot; there.
« Last Edit: July 25, 2008, 03:41:52 pm by SavannahLion »

boykster

  • This thread makes my brain hurt worse than Vogon poetry....
  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1581
  • Last login:February 04, 2025, 10:07:57 pm
  • The cake is a lie!
Re: XML formatting
« Reply #4 on: July 26, 2008, 07:42:32 pm »
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. 
« Last Edit: July 26, 2008, 07:45:41 pm by boykster »

Cakemeister

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1002
  • Last login:May 31, 2024, 06:23:16 pm
  • I'm a llama!
Old, but not obsolete.

Dartful Dodger

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3453
  • Last login:July 23, 2012, 11:21:39 pm
  • Newer isn't always better.
Re: XML formatting
« Reply #6 on: July 28, 2008, 04:01:33 pm »

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.