Get xml element problem

I need to get all codes from my xml. How i can do it ?

“Goods” is part of “GoodsShipment”

In for each i try this: DeserXml.Element(“CU_DOCUMENT”).Element(“GoodsShipment”).Elements(“Goods”)
but the error keeps appearing “For Each: Object reference not set to an instance of an object.”

also i needed to get “DocumentID” and i got it with this code
xNameSpaces = “{”+DeserXml.Root.GetDefaultNamespace.ToString+“}”

but that dont work for my “For each”, i try string like this DeserXml.Root.Element(“GoodsShipment”).Elements(“Goods”)

xml text:

<CU_DOCUMENT xmlns:cat_cu="*****" xmlns="*****" xmlns:cu="*****" DocumentModeID="*****">













Hi @Arettu63

Could you please provide the xml text, then it will be easier for us to extract the required data easily.

Hey @Arettu63

You can Iterate Through ‘Goods’ Elements:
In your ‘For Each’ activity, you should use the correct namespace to access the “Goods” elements.

DeserXml.Descendants(cuNamespace + “Goods”)

Inside the ‘For Each’ loop, use an ‘Assign’ activity to extract the ‘Code’ value. You can access it using something like item.Element(cuNamespace + "Code").Value

we would handle the XML Namespace

Thank you! now i can see the “Goods” elements, but i cant output the code.
Im use an ‘Assign’ and item.Element(cuNamespace + “Code”).Value inside it, error: Object reference not set to an instance of an object.

check that the sample / XML is valid
we do see an open Code but not closing the element
and a closing GoodDescription but dont see the opening tag

However use the immediate panel and analyze and prototype it further
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

I apologize, i misspelled it.
Currect text










Something is wrong with your xml.
Opening and closing tag is different:

here is solution for you: (2.9 KB)


for each:


i got result, but i wrote a line on my own. In for each item.Element(“cu_namespace” + “Code”).Value

There is a line at the top of the document:
<CU_DOCUMENT xmlns:cat_cu=“" xmlns="” xmlns:cu=“" DocumentModeID="”>
to refer to a “DocumentID” i need to use “xmlns:cat_cu” and for “Code” to “xmlns:cu” but how do i write it in code ?

@Arettu63 Try this solution: (2.9 KB)

That`s the solution, thank you! But what if i dont know the specific prefix? Is there any way to recognize it ?

I think that you can use it:


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