ADD AND DELETE A NODE IN XML FILE

Hi team ,

(Please see attached files)
I have built a code to add “Invoice_Line_Replacement_Data” node again in the xml file .
While doing that I was facing issues in adding 2 lines of nodes there wiz.

  1. <wd:ID wd:type=“Line_Number” wd:parent_id=“PO-00007288” wd:parent_type=“Document_Number”>3</wd:ID>

(Here I also want to update the value of wd:parent_id everyone (PO-00007288) as well as insert the line number )
2. <wd:ID wd:type=“Region_Reference_ID”>BRA</wd:ID>

(Here I want to update the region.For eg.BRA)

Similarly I want to delete these nodes also - I tried invoking “Remove” build was not able to do it -

I want to delete the below nodes -

  1. wd:Company_Reference
    <wd:ID wd:type=“Company_Reference_ID”>CMP2332131</wd:ID>
    </wd:Company_Reference>

2.wd:Invoice_Received_Date2022-07-28</wd:Invoice_Received_Date>

  1. (Is it possible to remove the node and its attributes entirely) since I want to remove this entire data in some cases
    wd:Invoice_Line_Replacement_Data
    wd:Purchase_Order_Line_Reference
    <wd:ID wd:type=“Line_Number” wd:parent_id=“PO-00007288” wd:parent_type=“Document_Number”>3</wd:ID>
    </wd:Purchase_Order_Line_Reference>
    wd:Quantity1</wd:Quantity>
    wd:Unit_Cost4.07</wd:Unit_Cost>
    wd:Worktags_Reference
    <wd:ID wd:type=“Region_Reference_ID”>BRA</wd:ID>
    </wd:Worktags_Reference>
    wd:Worktags_Reference
    <wd:ID wd:type=“Cost_Center_Reference_ID”>CC2342343809</wd:ID>
    </wd:Worktags_Reference>
    </wd:Invoice_Line_Replacement_Data>
  2. In some cases only
    wd:Worktags_Reference
    <wd:ID wd:type=“Cost_Center_Reference_ID”>CC2342343809</wd:ID>
    </wd:Worktags_Reference>

Please help for a solution
adding_PO_line.xaml (27.2 KB)

Regards,
Gokul

PO - Copy.xml (3.5 KB)
xml_addnode_deletenode.docx (841.0 KB)

Update →

I figured out the deletion part - just passing the element to be deleted in the Invoke Method with “Remove action”

xeLine_MainNode → xDoc.Root.Descendants(xnsWD + “Invoice_Line_Replacement_Data”)(1)

image

Please help me with the first two points

Regards,
Gokul

Hey @gokul1904 ,

One thing that has worked with my workday use cases is parsing the Xml as an XDocument, which will allow you to slice, dice and play around. Being part of System.Xml.Linq you should be able use lambdas at your convenience. See the references below for in-depth documentation.

/* this code sample is not the solution is just an example to showcase the XDocument Class
the code below gets specific nodes from an XDocument using lambda 
Remember every node can be parsed as an XDocument
In this example I'm extracting the "Attachment_Data" nodes 
xml_text variable is my XDocument */

extracted_nodes = xml_text.Descendants.Where(Function (element) element.Name.ToString.Contains("Attachment_Data")

References:

Read and Deserialize an XML file (uipath.com)
XDocument Class (System.Xml.Linq) | Microsoft Docs
XDocumentType Class (System.Xml.Linq) | Microsoft Docs
XContainer.Add Method (System.Xml.Linq) | Microsoft Docs
XContainer.RemoveNodes Method (System.Xml.Linq) | Microsoft Docs

1 Like

Hey Edwin ,

Thank you for the references which you gave above.
Unfortunately this is something urgent for which I need to find a solution.

Can you help me in adding the below xml node -

  1. <wd:ID wd:type=“Line_Number” wd:parent_id=“PO-00007288” wd:parent_type=“Document_Number”>3</wd:ID>

as I have highlighted in the above example.

Kind Regards,
G

@ppr Can you please help here.This one is very crucial for our project.

Regards,
G

I figured out the deletion part - just passing the element to be deleted in the Invoke Method with “Remove action”

xeLine_MainNode → xDoc.Root.Descendants(xnsWD + “Invoice_Line_Replacement_Data”)(1)

image

Please help me with the first two points

COPY PASTED FROM THE MAIN POST →
While doing that I was facing issues in adding 2 lines of nodes there wiz.

  1. <wd:ID wd:type=“Line_Number” wd:parent_id=“PO-00007288” wd:parent_type=“Document_Number”>3</wd:ID>

(Here I also want to update the value of wd:parent_id everyone (PO-00007288) as well as insert the line number )
2. <wd:ID wd:type=“Region_Reference_ID”>BRA</wd:ID>

(Here I want to update the region.For eg.BRA)

Regards,
Gokul

@Yoichi @ppr your valuable inputs would be really helpful here .thanks

Currently I am trying to add this element and attribute -
wd:Supplier_Invoice_Reference
<wd:ID wd:type=“Supplier_Invoice_Reference_ID”>1234</wd:ID>
</wd:Supplier_Invoice_Reference>
I am able to do this
wd:Supplier_Invoice_Reference
<wd:ID type=“Supplier_Invoice_Reference_ID”>1234</wd:ID>
</wd:Supplier_Invoice_Reference>

with

but I want wd:type as the name

so when I try with


I am getting this error -

Can you please help here

Regards

Okay I figured it out -

Added this and it is resolved.

Please find the updated code modules for solution here -
adding_PO_line.xaml (34.4 KB)

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