Click here to Skip to main content
16,007,163 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a block of data that represents a location on a map
It has the following fields:
X, Y, Index.
The xml will be used in C# App
What is the best practice way
to define this data in xml:
1.
XML
<location>
  <X>
    100
  </X>
  <Y>
    200
  </Y>
  <Index>
    4
  </Index>
</location

2.
XML
<location>
   X=100
   Y=200
   Index=4
</location>
Posted
Updated 6-Jun-13 5:53am
v2

Have a look at xml-attributes-vs-elements[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Jun-13 12:18pm    
OP does not consider attributes vs. element. Take a look at the question again: it's elements vs. unstructured trash. :-)
—SA
I think the first approach is best. This will make your xml parsing easy as well.

<location>
<X>100</X>
<Y>200</Y>
<Index>4</Index>
</location>
 
Share this answer
 
Second one it simply unacceptable, period. Do you want to parse the single text node you demonstrated into three parameters? And what do you think, what the XML parser is used for? (However, such practice is sometimes used, if the text is really big, and the parser is already available…)

—SA
 
Share this answer
 
I would suggest the third approach in this scenario: attributes. Look at the following sample:

XML
<locations>
 <location index="1" x="100" y="200" />
 <location index="2" x="10" y="20" />
 <location index="3" x="40" y="50" />
</locations>

It looks clearer, doesn't it?
Of course there can be considerations where this isn't the good practice (I suggest you look at the thread linked by learner'sbug, and the articles referred there). But as in this situation we have a simple list of elements with fixed and really simple structure, it might be considered.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900