Let’s say you have to get some data from a XML provided by a 3rd party. You don’t have access or rights to modify that XML and the semantic, well, is not as good as you, semantic lover, would like to. In fact, let’s face it, the XML sucks in semantic and it has tables inside that makes you remember the nineties and those HTMLs.
First thing you do is a XPath expression based on hardcoded indexes, of course. “Please sir, would you mind to give me the TR[4] from TD[1]? Yes, I already know where is this data from, thanks”. But let’s imagine for a moment that your friend, the 3rd party, decide one day to change the XML, oor simply to change the order of the fields in the table, oor to add more fields to the table, oor… You don’t want to be dependent on the 3rd party mood to change your code and your XPath expressions one day and another, right? So better live without hardcoded indexes, if you can.
But… how? I had to fight with two scenarios, and I managed to get it done without hardcoded indexes. Of course your mileage may vary, but here’s how I did it:
(more…)
September 24th, 2008 | Development, English | Wanna say something?