Import an XML with a colon (:) in the xpath

2

I'm trying to import an XML into a Google spreadsheet with importXML .

I can extract all the fields as:

=importXML( URL, "//item/loquequiero")

But with the fields that start with g: I get an error and I do not understand why.

How can I solve it?

<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <title>Whirlpool Argentina</title>
    <description>...</description>
    <link>www.whirlpoolstore.com.ar</link>
    <item>
        <g:id>
            <![CDATA[ 107 ]]>
        </g:id>
        <title>
            <![
                Aire Acondicionado Whirlpool - 3000 FC - Frio/Calor - Blanco
            ]]>
        </title>
        <description>
            <![CDATA[ (WB230AB) ]]>
        </description>
        <g:product_type>
            <![CDATA[ Electrodomésticos - Aires Acondicionados ]]>
        <g:product_type>
        <g:brand>
            <![CDATA[ Whirlpool ]]>
        </g:brand>
        <g:mpn>
            <![CDATA[ WB230ANACJ ]]>
        </g:mpn>
        <g:gtin>
            <![CDATA[ WB230ANACJ ]]>
        </g:gtin>
        <link>
            <![CDATA[
                http://www.whirlpoolstore.com.ar/aire-acondicionado-whirlpool-3000-fc-frio-calor-blanco/p?idsku=107
            ]]>
        </link>
        <g:image_link>
            <![CDATA[
                http://www.whirlpoolarg.vteximg.com.br/arquivos/ids/155739_2
            ]]>
        </g:image_link>
        <g:price>
            <![CDATA[ 10.949,25 ]]>
        </g:price>
        <g:installment>
            <g:months>
                <![CDATA[ 1 ]]>
            </g:months>
            <g:amount>
                <![CDATA[ 10,949.25 ARS ]]>
            </g:amount>
        </g:installment>
        <g:condition>new</condition>
        <g:availability>in stock</availability>
    </item>
    
asked by César Requena 09.03.2017 в 17:53
source

1 answer

1

In the source code of the displayed XML file g: is used as a prefix to indicate that the name of the node corresponds to a namespace, which is specified as the line:

<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">

One way to specify the node is to use [nombre()='loquequiero'] .

Example

Assume that A1 has the URL of the XML file, and A2 has the name of the node that interests us (without the prefix g: , we gave loquequiero .) A formula to get all the nodes g:loquequiero is the following :

=IMPORTXML(A1,"//*[name()='"&A2&"']"

Related:

My answer in English at How to Import XML table Google Sheets

    
answered by 12.03.2017 в 05:12