I need to retrieve the data node, and parse every unit into something
like this:
Your data provider does not want you to parse the given XML. They have gone into a lot of trouble to make it especially difficult for you. If you cannot persuade them to change their format, then I suggest you take the following steps:
Step 1: Apply the following stylesheet to the input XML:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://tempuri.org/"
exclude-result-prefixes="ns">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/ns:Response">
<result>
<xsl:value-of select="ns:Result" disable-output-escaping="yes"/>
</result>
</xsl:template>
</xsl:stylesheet>
and save the result to a file.
Step 2: Apply the following stylesheet to the file produced in step #1:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/result">
<xsl:value-of select="data" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
and save the result to a file.
Step 3: Apply the following stylesheet to the file produced in step #2:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/unitlist">
<units>
<xsl:for-each select="unit">
<xsl:copy>
<id>
<xsl:value-of select="@unitid" />
</id>
<name>
<xsl:value-of select="@name" />
</name>
<abbreviation>
<xsl:value-of select="@abbreviation" />
</abbreviation>
</xsl:copy>
</xsl:for-each>
</units>
</xsl:template>
</xsl:stylesheet>
For clarity, these are the results you should get in each step:
Step 1
<?xml version="1.0" encoding="UTF-8"?>
<result>
<resultcode>0</resultcode>
<message>OK</message>
<data><unitlist version="1"><unit version="1" unitid="%" abbreviation="%" name="Porcentaje" />
<unit version="1" unitid="1/2 lb." abbreviation="1/2 lb." name="1/2 libra" /><unit version="1" unitid="1/2 pt." abbreviation="1/2 pt." name="medias pintas" /><unit version="1" unitid="1/2 pulg." abbreviation="1/2 pulg." name="1/2 pulg." /><unit version="1" unitid="1/2&quot; cdr." abbreviation="1/2&quot; cdr." name="1/2 pulgada cuadrada" /></unitlist></data>
</result>
Step 2
<?xml version="1.0" encoding="UTF-8"?>
<unitlist version="1"><unit version="1" unitid="%" abbreviation="%" name="Porcentaje" />
<unit version="1" unitid="1/2 lb." abbreviation="1/2 lb." name="1/2 libra" /><unit version="1" unitid="1/2 pt." abbreviation="1/2 pt." name="medias pintas" /><unit version="1" unitid="1/2 pulg." abbreviation="1/2 pulg." name="1/2 pulg." /><unit version="1" unitid="1/2" cdr." abbreviation="1/2" cdr." name="1/2 pulgada cuadrada" /></unitlist>
Step 3
<?xml version="1.0" encoding="UTF-8"?>
<units>
<unit>
<id>%</id>
<name>Porcentaje</name>
<abbreviation>%</abbreviation>
</unit>
<unit>
<id>1/2 lb.</id>
<name>1/2 libra</name>
<abbreviation>1/2 lb.</abbreviation>
</unit>
<unit>
<id>1/2 pt.</id>
<name>medias pintas</name>
<abbreviation>1/2 pt.</abbreviation>
</unit>
<unit>
<id>1/2 pulg.</id>
<name>1/2 pulg.</name>
<abbreviation>1/2 pulg.</abbreviation>
</unit>
<unit>
<id>1/2" cdr.</id>
<name>1/2 pulgada cuadrada</name>
<abbreviation>1/2" cdr.</abbreviation>
</unit>
</units>
The alternative is to extract the data using string functions, which would be extremely tedious and error-prone.