Cannot get value from .xml file

Guys,

After 4 hours, I am really desparate.

Trying to get the value of MsgId but UiPath always says “Object reference not set to an instance of an object.”.

This is how xml looks like.
Untitled

This my command:
xmlDoc.Element(“Document”).Element(“BkToCstmrStmt”).Element(“GrpHdr”).Element(“MsgId”).Value

I did everything according to all topics here, but nothing helps.

@mario
Your XML ist defining a namespace so the element Name is Not only the so called local Name.

Just Log Out for Exploration the Name of the root element and notice the full quallified Name

Have a Look Here for an example Implementation

I’m not sure what the data type of your xmlDoc is, but if you use the System.Xml.Document data type you can select the value of the node like this:

xmldoc.DocumentElement.SelectSingleNode("/Document/BkToCstmrStmt/GrpHdr/MsgId").InnerText

This is provided there is only one node like this. If there are more than one, use SelectNodes instead an loop through them. And use the InnerText parameter, not Value.

Hope that helps.

Hi,

xmlDoc is System.xml.Linq.XDocument and this variable type does not allow to use command as DocumentElement

When I open my .xml file in Notepad, it seems that it is not split into lines. Is it ok?

yes, that dont interfere with xml parsing.

@mario aslong XML ist valid its ok

to be honest if the only thing you need from this xml is to get that value, is not worth the hassle to parse the xml, just parse it as text and get the value…

@mario
Another Option Could be to remov manually the namespace information from root element, then your Code from above Could again work

Can you post the XML you have @mario?

WIll try to do the requirement

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