Xml import actions are not working with namespaces

Xml import actions are not working with namespaces

Good Morning,

I am ipmorting an XLIFF/XML file. What I observed is that when my root tag contains namespaces, it is not reading my xml file and returning me node count as "0" when I am specifying XPATH string.

But when I replace tags having namespaces with simple tag, it is reading my XML file and giving me correct node count.

I am facing this issue for actions inside Xml extension.

Is there any other way to read XML files with namespaces? I don't want to get into the habit of replacing namespaces with simple tag names because for now I know which tags will contain namespaces and which tag won't. What if customer is providing XML with missing one/two namespaces.

Please advice.

Thanks and Regards,
Suraj Borade
Hi Suraj,

I believe your problem is not related to the extension or OutSystems, but with the XPath standard itself and it behavior when using XML namespaces.

Basically the XPath query needs to be change to take into consideration the use of namespaces.

Take a look into this simple example:


If I select XPath /Fields/Field/text() it will return "MyValue" as expected.

If I use the a XML with namespace:

<Fields xmlns="x">

The previous query returns no results, however if you use this one you get the same result, even on a scenario where the xml uses a namespace:

/*[namespace-uri()='x' and local-name()='Fields']/*[namespace-uri()='x' and local-name()='Field']/text()

Hope it helps

Hi Carlos,

Thanks a lot for the reply. 

Can you please explain in detail this XPATH
*[namespace-uri()='x' and local-name()='Fields']/*[namespace-uri()='x' and local-name()='Field']/text()

because in next step, I will be giving more XPATHs like this  
 In this case I want all trans-unit nodes with attribute name = id.

How should I redefine XPATH for this case?

Thanks a lot.

Best Regards,
Suraj Borade


I an no Xpath ninja :) , however based on the info you're providing me I'dd say you have a XML that (in very simple terms) would be something like this:

<trans-unit xmlns="http://server/namespace">
    <field id="CORE_IDEA">Value Core</field>
    <field id="NOT_CORE_IDEA">Value Not Core</field>

If you use XPath /*[namespace-uri()='http://outsystems.com/namespace' and local-name()='trans-unit']/*[namespace-uri()='http://outsystems.com/namespace' and local-name()='field'][@id='CORE_IDEA']/text()

you'll get the "Value Core" value.

Hope it helps.
Hi Carlos,

Thanks. I will check and will update you.

-- Suraj B