# Get xml element problem

**URL:** <https://forum.uipath.com/t/get-xml-element-problem/711506>\
**Category:** StudioX\
**Tags:** xml, question, studio\
**Created:** [January 10, 2024, 12:24pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506 "2024-01-10T12:24:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arettu63](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arettu63/32/177094_2.png) [@Arettu63](https://forum.uipath.com/u/Arettu63)\
**Post date:** [January 10, 2024, 12:24pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/1 "2024-01-10T12:24:06Z")

</div>

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

“Goods” is part of “GoodsShipment”

 ![image001 (1)](https://global.discourse-cdn.com/uipath/original/4X/d/8/c/d8c09fd41c9af06d04e6f09c0be5d5dfbbc7ea1c.png)

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+“}”  
DeserXml.Root.Element(xNameSpaces+“DocumentID”).Value

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

xml text:

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

<cat_cu:DocumentID>123456789</cat_cu:DocumentID>

<AAA>firstString</AAA>

<GoodsShipment>

<Goods>

<cu:GoodsNumeric>1</cu:GoodsNumeric>

<cu:Code>1283</cu:GoodsDescription>

<Goods>

<cu:GoodsNumeric>1</cu:GoodsNumeric>

<cu:Code>2351</cu:GoodsDescription>

<Goods>

<cu:GoodsNumeric>1</cu:GoodsNumeric>

<cu:Code>1654</cu:GoodsDescription>

```

---

<div class="post-metadata">

**Author:** ![mkankatala](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mkankatala/32/484097_2.png) [@mkankatala](https://forum.uipath.com/u/mkankatala)\
**Post date:** [January 10, 2024, 12:25pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/2 "2024-01-10T12:25:39Z")

</div>

Hi @Arettu63

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

---

<div class="post-metadata">

**Author:** ![pikorpa](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pikorpa/32/548059_2.png) [@pikorpa](https://forum.uipath.com/u/pikorpa)\
**Post date:** [January 10, 2024, 1:02pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/3 "2024-01-10T13:02:45Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [January 10, 2024, 1:05pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/4 "2024-01-10T13:05:00Z")

</div>

we would handle the XML Namespace

> [@XML Extraction - Handling Namespaces (Tableau, Soap, OASIS types)](https://forum.uipath.com/t/xml-extraction-handling-namespaces-tableau-soap-oasis-types/401623/3):
>
> Going ahead Serializing the XML - output: xDoc | DataType: XDocument: [grafik] Checking if we have to handle XML namespaces We do have: [grafik] Checking for some children: [grafik] Defining Namespace Variable bulb In some cases, we can also do: Assign Activity - xnsDefault = xDoc.Root.Name.Namespace Checkin the retrieval [grafik] xDoc.Descendants(xnsDefault + "productVersion") GetDescendants { [\<productVersion build="456" xmlns="http://tableau.com/api"\>123\</…

---

<div class="post-metadata">

**Author:** ![Arettu63](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arettu63/32/177094_2.png) [@Arettu63](https://forum.uipath.com/u/Arettu63)\
**Post date:** [January 10, 2024, 1:31pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/5 "2024-01-10T13:31:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [January 10, 2024, 1:48pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/6 "2024-01-10T13:48:00Z")

</div>

check that the sample / XML is valid  
 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/4/2/7/427be39265a00917d69196223340a3b1264c9e12.png)  
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](https://forum.uipath.com/t/understanding-the-6-debugging-panels-of-uipath-in-the-easiest-way-possible/353606)

---

<div class="post-metadata">

**Author:** ![Arettu63](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arettu63/32/177094_2.png) [@Arettu63](https://forum.uipath.com/u/Arettu63)\
**Post date:** [January 10, 2024, 1:51pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/7 "2024-01-10T13:51:03Z")

</div>

> [@Arettu63](#):
>
> ```auto
> <Goods>
> 
> <cu:GoodsNumeric>1</cu:GoodsNumeric>
> 
> <cu:Code>1283</cu:GoodsDescription>
> 
> <Goods>
> 
> <cu:GoodsNumeric>1</cu:GoodsNumeric>
> 
> <cu:Code>2351</cu:GoodsDescription>
> 
> <Goods>
> 
> <cu:GoodsNumeric>1</cu:GoodsNumeric>
> 
> <cu:Code>1654</cu:GoodsDescription>
> 
> ```

I apologize, i misspelled it.  
Currect text

```auto
<Goods>

<cu:GoodsNumeric>1</cu:GoodsNumeric>

<cu:Code>1283</cu:Code>

<Goods>

<cu:GoodsNumeric>1</cu:GoodsNumeric>

<cu:Code>2351</cu:Code>

<Goods>

<cu:GoodsNumeric>1</cu:GoodsNumeric>

<cu:Code>1654</cu:Code>

```

---

<div class="post-metadata">

**Author:** ![pikorpa](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pikorpa/32/548059_2.png) [@pikorpa](https://forum.uipath.com/u/pikorpa)\
**Post date:** [January 10, 2024, 1:52pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/8 "2024-01-10T13:52:15Z")

</div>

Something is wrong with your xml.  
Opening and closing tag is different:  
`<cu:Code>1283</cu:GoodsDescription>`

---

<div class="post-metadata">

**Author:** ![pikorpa](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pikorpa/32/548059_2.png) [@pikorpa](https://forum.uipath.com/u/pikorpa)\
**Post date:** [January 10, 2024, 1:56pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/9 "2024-01-10T13:56:42Z")

</div>

@Arettu63  
here is solution for you:  
[BlankProcess66.zip](https://forum.uipath.com/uploads/short-url/2puiVwlBvOXag8WLMb7QtUZIYHf.zip) (2.9 KB)

XNamespace:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/a/a/a/aaa39824b4574f2079a5724464abd3f853ed5b2d.png)

for each:  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/4/e/74e4ba82068d30fce49ab45165908de0c9ef4741.png)

---

<div class="post-metadata">

**Author:** ![Arettu63](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arettu63/32/177094_2.png) [@Arettu63](https://forum.uipath.com/u/Arettu63)\
**Post date:** [January 10, 2024, 1:58pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/10 "2024-01-10T13:58:41Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![pikorpa](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pikorpa/32/548059_2.png) [@pikorpa](https://forum.uipath.com/u/pikorpa)\
**Post date:** [January 10, 2024, 2:01pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/11 "2024-01-10T14:01:35Z")

</div>

@Arettu63 Try this solution:  
[BlankProcess66.zip](https://forum.uipath.com/uploads/short-url/2puiVwlBvOXag8WLMb7QtUZIYHf.zip) (2.9 KB)  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/5/c/75c2db902211fefec303e8bd148184792232bb22.png)

---

<div class="post-metadata">

**Author:** ![Arettu63](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/arettu63/32/177094_2.png) [@Arettu63](https://forum.uipath.com/u/Arettu63)\
**Post date:** [January 10, 2024, 2:03pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/12 "2024-01-10T14:03:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pikorpa](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pikorpa/32/548059_2.png) [@pikorpa](https://forum.uipath.com/u/pikorpa)\
**Post date:** [January 10, 2024, 2:08pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/13 "2024-01-10T14:08:30Z")

</div>

I think that you can use it:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/c/8/6/c8617bcc0352bf5660874d350717d7cd8ee410a1.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [January 13, 2024, 2:08pm UTC](https://forum.uipath.com/t/get-xml-element-problem/711506/14 "2024-01-13T14:08:38Z")

</div>

Closed on January 13, 2024, 2:08pm UTC

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