Get a specific node/content from XML

Hello i have an call where i get an XML response back. I am trying to fetch a specific value from that call and assign it. I do get response back so the call is working, but not sure how to narrow down to the correct level to get the value

this is what I have now
image

and I want the Key value

1 Like

Hey!

Try this:

System.Text.RegularExpressions.RegEx.Match(InputStringVariable,"(?<=<key>).*(?=<.key>)").ToString

Reference:

Regards,
NaNi

Hey @langsem

De-serialize XML into an XML object and access the value with its key.

Hope that helps.

Thanks
#nK

Already have de-serialize :stuck_out_tongue:
It fails when i do the assign . “Object reference not set to an instance of an object”

1 Like

Hey @langsem

Could you please share your XML as text here.

I can share you a workflow demo.

Thanks
#nK

Hi @langsem,

Welcome back to posting on the forums!

There are numerous ways that you could extract the specific XML Node Content some more straight forward than another depending on how complex the XML structure is. You could use Regular Expressions on more simple XML, access the DOM among others, but typically my go to is XPath (XML Path Language).

(Sidebar! When asking the community for assistance it is often a curtesy to provide the raw source when possible of the data you are working in, that way it becomes more accessible to those the desire to help out. I’ve taken the liberty of of using OCR and will provide the XML in text form below)

<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
  <Soap:Body>
    <Read_Result xmlns="">
	  <SetReadPostedSalesInvoices>
	    <Key>32;cAAAAAJ7CDgAMAAwADAAMAA2ADgAOQ==10;11301131180;</Key>
	    <No>80000689</No>
	    <SQ_Date_Picked>2022-07-11</SQ_Date_Picked>
	    <SQ_Time_Picked>11:34:00.0000000</SQ_Time_Picked>
	  </SetReadPostedSalesInvoices>
	</Read_Result>
  </Soap:Body>
 </Soap:Envelope>

As a simple example of XPath we can do the following

  1. Read/Load the XML
  2. Deserialize the XML
  3. Execute our XPath Query

image

XPath Query: "string(//SetReadPostedSalesInvoices/Key)"
Results: 32;cAAAAAJ7CDgAMAAwADAAMAA2ADgAOQ==10;11301131180;

What we are asking for is search (//) for node with name of SetReadPostedSalesInvoices that also has a child-node of name Key

Assuming it will always be a single node/element we are expecting, we then can convert the resulting XPath object into a String using the fn:string() function, otherwise you could leave off the string function and would get an object with an array of elements found.

image

^^ In the above I duplicated the <SetReadPostedSalesInvoices> element.

I have a few older posts that I provide some XPath examples and lots more information on the Internet!