I cant access XML nodes in complex XML-file

Hello everyone!

I have been trying to access nodes in my Xml template which I have stored in xDocument variable in Uipath.
However with this structure I cant seem to do it. If I cut out lines and leave only and its contents, I can access nodes and edit them just fine. This is the xml. I edited out some bits.

What am I doing wrong? I have tried several different tricks and tried adding namespaces too.
This is how I try to access node counts right now:

xml.Element(ns2+“item”).Elements.Count.ToString

I have also tried accessing sinlge node this way:

xml.Element(ns2+“item”).Element(“p3”).Value

where ns2 is namespace “schema-url” in this case (edited).

Thank you for reading.

can you provide a file for testing?

Sadly I cant since my user is new. I can copypaste the contents of xml though.

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Body>
    <MBCP2:update name="zzzzz" user="user" id="2019-14-05 10:30:57-00160731-123456789123456" xmlns:MBCP2="schema-url">
      <CommandName commandtype="procedure">
	<item>
	<p0 parametertype="InputOutput"></p0>
	<p1 parametertype="InputOutput"></p1>
	<p2 parametertype="InputOutput"></p2>
	<p3 parametertype="InputOutput">xxxxxx</p3>
	<p4 parametertype="InputOutput">xxx</p4>
	</item>
      </CommandName>
    </MBCP2:update>
  </soap:Body>
</soap:Envelope>

Thanks, there is certainly a more elegant way to achieve this, but if you provide the Element name you wish to access to this workflow, it will return the value of that element.

So for example, ‘p4’ will return the value ‘xxx’. If you are doing a heavy amount of processing like this however, it may be better to access the various nodes as you are attempting, which would be the traditional way of working with XMLs.

It just depends

IterateXML_Example2.zip (2.1 KB)

Thank you for your answer. However second activity in this workflow seems to be missing on my end, any idea why that happens?

You say that it may be better to access the nodes like I am attempting, but I cant do it. Do you know how to achieve this?

Ah, so you need to ensure you have the correct activity package installed to allow the XML to be deserialised:

image

Thank you for your answer. However I would need to edit those node values in my template and call a service with this xml after. I still dont know how to edit those nodes. Do you have an idea how to achieve this?

Sure, you are acting on an XDoc when searching the Nodes. So you can use the following syntax to update the value to what you need, then just export the resulting XDoc to a text for example.

IterateXML_UpdateValues.zip (2.3 KB)

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