maestro360 — 2011-12-12T16:37:23-05:00 — #1
I have a company generating a daily XML feed I'll have to parse. One of the first things I've noticed is there are 3 <categoryName> tags.
Am I correct in assuming this is bad form?
I'd be parsing it with either PHP's DomDocument or SimpleXML and I'm not sure if these duplicate tags would break my parsing code.
An interesting sidenote, if any instances of the <categoryName> tag have no data to display, they're generated as empty <categoryName/>. So perhaps they're necessary for the software generating the feed?
maestro360 — 2011-12-14T11:01:54-05:00 — #2
I suppose I could target these elements based on where they're placed in the XML tree.
Any other thoughts?
scallioxtx — 2011-12-14T14:19:18-05:00 — #3
Yes that is indeed pretty bad form, especially if different nodes contain different values.
Indeed, you could check by position, and hope for the best. That's what I would do as well.
Also, I'd store all the other values you get as well, even if you don't do anything with them. Just so you have them and don't have to come back later if you find you picked the wrong one. With the prices of storage nowadays that shouldn't matter.
wwb_99 — 2011-12-15T14:00:01-05:00 — #4
I'm guessing you are talking about something that looks like:
If so, that is often used to represent an array of values in XML. No real big issue with it IMHO. I could tell you how to handle it with C# and .NET XML Deserialization but that probably won't help here.
maestro360 — 2011-12-17T01:03:52-05:00 — #5
Thank you both for your input. wwb_99, yes that's how the tags are formatted. Interesting to hear there might be a legitimate reason for why duplicated tags are being used. I feel though someone at the other end of this xml file is taking the lazy approach. I'm sure it wouldn't be much work to parse each of the array attributes into unique nodes. Though these nodes are the only children of their own parent node, so targeting them specifically should be pretty easy. I'll just have to figure out how the PHP XML parsing libs do it.
scallioxtx — 2011-12-17T05:39:44-05:00 — #6
The correct way to create arrays in XML is IMO:
Just makes the most sense, semantically.
Then again, the best XML is no XML at all
I'm a huge json fan. I find it makes life so much easier.
Of course, we don't always get to pick and need to row with the peddles that are handed to us.
wwb_99 — 2011-12-17T15:06:40-05:00 — #7
That definitely makes a little more sense but they are really six of one half dozen of the other. Same with json -- it is nice and a little more readable, but the flip side is there are things one can do with xml that you can't do with json.
In any case, remember one should never parse xml or json. They aren't text but rather serialized representations of objects. So remember to deserialize them.