mario
(Mario)
October 10, 2019, 8:17pm
1
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.
This my command:
xmlDoc.Element(“Document”).Element(“BkToCstmrStmt”).Element(“GrpHdr”).Element(“MsgId”).Value
I did everything according to all topics here, but nothing helps.
ppr
(Peter Preuss)
October 10, 2019, 9:24pm
2
@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
Hi @mikamol
Find the attached sample Main.xaml (8.1 KB)
that is showcasing following:
Retrieving all Field elements
Retrieving all Id elements (Parent is Field)
Retrieving the particular Answer Value for a particular Id
As this XML is defining the namespace:` xmlns="urn:abou:documents:ka:Case
The Root element Name is not Case it is: e.g. urn:abou:documents:ka:Case:Case
So the namespace part is to take into account
Solved with using namespace manager
Kindly note the order from a XML Docu…
Tuhdae
October 10, 2019, 9:24pm
3
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.
mario
(Mario)
October 10, 2019, 9:32pm
4
Hi,
xmlDoc is System.xml.Linq.XDocument and this variable type does not allow to use command as DocumentElement
mario
(Mario)
October 10, 2019, 9:33pm
5
When I open my .xml file in Notepad, it seems that it is not split into lines. Is it ok?
bcorrea
(Bruno Correa)
October 10, 2019, 9:35pm
6
yes, that dont interfere with xml parsing.
ppr
(Peter Preuss)
October 10, 2019, 9:35pm
7
@mario aslong XML ist valid its ok
bcorrea
(Bruno Correa)
October 10, 2019, 9:38pm
8
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…
ppr
(Peter Preuss)
October 10, 2019, 9:45pm
9
@mario
Another Option Could be to remov manually the namespace information from root element, then your Code from above Could again work
HareeshMR
(Hareesh Madasi)
October 11, 2019, 2:45pm
10
Can you post the XML you have @mario ?
WIll try to do the requirement
system
(system)
Closed
October 14, 2019, 2:45pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.