Attribute from XML file

Hi
I am trying to parsing “OrderID” from below mention xml file.

Tried to display the attribute after “Deserialize” activity as “dt_xml.Element(“Request”).Element(“OrderRequest”).Element(“OrderRequestHeader”).Attribute(“orderID”).ToString” but getting Message Box: Object reference not set to an instance of an object.


Can some please help me if I am doing something wrong? Thanks

@Naresh_Upadhyay
on the first look the retrieval is reasonable, but unfortunately we cannot inspect all details.

For a first analysis round do following:

  • check all variables and scopes (no duplicates, no scope confusions)

  • set a breakpoint to activity next after deserialize XML

  • go for debugging and open the watch / or immediate panel
    type in following commands and share the output with us:

     dt_xml.Root.Name.toString 
     dt_xml.Root.Descendants(24).Name.toString
     dt_xml.Root.Descendants("OrderRequestHeader")(0)
    

with this check we want to find out:

  • not null XDocument dt_xml
  • namespace used within names
  • general retrieval success

based on the results we will help your for the next steps

Here is the output.
dt_xml.Root.Name.toString
“cXML”
dt_xml.Root.Descendants(24).Name.toString
Cannot evaluate ‘dt_xml.Root.Descendants(24).Name.toString’ at current context.
dt_xml.Root.Descendants(“OrderRequestHeader”)(0)
[











FedEx Ground


00
0
0
0
0
EDI Generated Order


0
0
0
0
0
Deliver to remote address


0
0
0
0
0
Are you replacing an existing machine or requesting addition


0
0
0
0
0
hardware?:Replacement, What asset are you replacing?:1204653


0
0
0
0
0
you requesting this?:My machine is broken., Please provide












]

@Naresh_Upadhyay

please use the format button </> form editor or do screenshot (have a look on your post)

One good thing as expected no namespace is to handle. Is it ensured that the correct XML is loaded?

can you also check:
dt_xml.Root.Descendants(“OrderRequestHeader”)(0).Attributes

Here is the result.
GetAttributes
{
[orderDate=“2020-10-23T08:47:11-08:00”],
[orderID=“2599030094”],
[orderType=“regular”],
[orderVersion=“1”],
[type=“new”],
[requisitionID=“”],
[mailDate=“20200908”]
}

@Naresh_Upadhyay
this are good news as the order ID is correct, right?

is following working?
dt_xml.Root.Descendants(“OrderRequestHeader”)(0).Attribute(“orderID”).Value.toString

1 Like

Great!! It’s working.
Thank you so much!!!

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