Parsing tables with XPath without hardcoded indexes

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…)

Compártelo
September 24th, 2008 | Development, English | Wanna say something?

Just a thought

Compártelo
September 23rd, 2008 | English, Thoughts | One comment

Justice Live @ I Love Techno

Compártelo
September 9th, 2008 | Music | 2 comments

José González - Live in Berlin

Compártelo
July 7th, 2008 | Music | One comment

Updating Nginx to the 0.6.x branch

Compártelo
June 23rd, 2008 | English, Projects, Web | Wanna say something?

True Story

Compártelo
June 4th, 2008 | English, Paridas | Wanna say something?

Installing Munin plugins for Memcached and Nginx

Compártelo
April 21st, 2008 | Development, English | Wanna say something?

Updating Wordpress with Subversion

Compártelo
April 18th, 2008 | Development, English, Web | 2 comments

Automatically version your Javascript files with Subversion

Compártelo
February 17th, 2008 | Development, English, Javascript, PHP, Python | Wanna say something?

Visualizeus en la tele!

Compártelo
January 25th, 2008 | Projects | 3 comments

Categories

Syndication

my favorite pictures

    Archives

    Cerrar
    Enviar por Correo