Error While reading specific element value from XML, when XML has namespace

I wish to get value of Element “name” which is inside “homecity”. (see the xml below)

Here is what I’ve tried -

  1. Read XML using Read Text File activity and stored the output in “xmlContent” variable.
  2. Used the Parse method to parse the xmlContent from Step 1, assigned to a XDoc variable of XDocument type.
  3. Used, XDoc.XPathSelectElement(“//homecity/name”).Value and assigned this to a “cityName” variable.
    NOTE: Have also tried Deserializing XML. And, when I remove the xmlns="" from person and "xmlns="" from homecity, it works.

After executing this getting Runtime execution error -

Source - Assign (Step 3)
Message - Object reference not set to an instance of an object
Exception Type: System.NullReferenceException

Here is the xml which I’m using -

<person xmlns="">
    <homecity xmlns="">

Any suggestions on this would be of great help. Thanks!

XML Extraction - Handling Namespaces (Tableau, Soap, OASIS types) - Help / Community - UiPath Community Forum

here we would work with a namespace manager

@ppr - Thanks, Peter!

But I don’t wish to have the namespaces added to data sheet. Is there anyway I can get the element value from the given xml (mentioned in my question) or anyway to just ignore the namespaces and read the rest of the xml.

it is not about to setup a config and namespaces to a config table. It was about to show you the essentials on how to setup up the namespace manager needed for the XPathSelectElement

we had shown you two approaches and did answer how to handle XML Namespaces

not really recommended, as we can properly handle the Namespaces

A Variation with XPath:

Thanks a lot Peter for your assistance, it helped and worked!


Perfect, so the topic can be closed by:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.