Avoiding Redundancies in XML documents
Posted
by MarceloRamires
on Stack Overflow
See other posts from Stack Overflow
or by MarceloRamires
Published on 2010-03-24T13:06:36Z
Indexed on
2010/03/24
13:23 UTC
Read the original article
Hit count: 381
I was working with a certain XML where there were no redundancies
<person>
<eye>
<eye_info>
<eye_color>
blue
</eye_color>
</eye_info>
</eye>
<hair>
<hair_info>
<hair_color>
blue
</hair_color>
</hair_info>
</hair>
</person>
As you can see, the sub-tag eye-color makes reference to eye in it's name, so there was no need to avoid redundancies, I could get the eye color in a single line after loading the XML into a dataset:
dataset.ReadXml(path);
value = dataset.Tables("eye_info").Rows(0)("eye_color");
I do realise it's not the smartest way of doing so, and this situation I'm having now wasn't unforeseen.
Now, let's say I have to read xml's that are in this format:
<person>
<eye>
<info>
<color>
blue
</color>
</info>
</eye>
<hair>
<info>
<color>
blue
</color>
</info>
</hair>
</person>
So If I try to call it like this:
dataset.ReadXml(path);
value = dataset.Tables("info").Rows(0)("color");
There will be a redundancy, because I could only go as far as one up level to identify a single field in a XML with my previous method, and the 'disambiguator' is three levels above.
Is there a practical way to reach with no mistake a single field given all the above (or at least a few) fields ?
© Stack Overflow or respective owner