troubleshooting Question

How can I update these XML values if they have been updated, when parsing XML in C#?

Avatar of Jordan Johnson
Jordan Johnson asked on
3 Comments1 Solution158 ViewsLast Modified:
I am parsing XML to update if changes are made. A check is done to see if the order already exists, and if so, doesn't add the invoice rows. However, how can I go about modifying the values if they are updated? Since these are nodes within nodes and whatnot, I have also added the XML example here, with the included invoiceRows.


<?xml version="1.0" encoding="UTF-8"?>

-<InvoiceOrder xmlns:xsd="" xmlns:xsi="">

<OrderId xmlns="">88844165</OrderId>

<CustomerId xmlns="">7</CustomerId>

<CustomerName xmlns="">Test Company</CustomerName>

-<Addresses xmlns="">


<Street>Chestnut Avenue</Street>


<PostalCode>SO53 ABC</PostalCode>

<Name>Test House</Name>





<Street> 56 Test Street</Street>

<PostalCode>BL4 8BE</PostalCode>

<Name>Mrs Hughes</Name>





<OrderStatus xmlns="">Invoiced</OrderStatus>

<DateOrdered xmlns="">2015-11-02</DateOrdered>


<IncludeVAT xmlns="">True</IncludeVAT>

-<Currency xmlns="">



<TypeOfSaleId xmlns="">-100</TypeOfSaleId>

-<InvoiceRows xmlns="">





<Name>CADENCE RAD</Name>


















Open in new window

C# Code

bool orderidfound = false; //checks whether order already exists

                                                    for (int k = 0; k < po.Length; k++)
                                                        if (po[k].OrderId == Convert.ToInt32(fileref.importList["OrderId"].InnerText)) //if order number is equal
                                                            orderidfound = true;

                                                    if (orderidfound == false) //ensures duplicate invoice rows are not added

                                                        newInvoice.InvoiceRows = order.Elements(ns + "InvoiceRows")
                                                        .Elements(ns + "InvoiceRow")
                                                        .Select(e => new Invoices.InvoiceRow

                                                            ProductId = e.Element(ns + "ProductId") == null ? 0 : (int)e.Element(ns + "ProductId"),
                                                            RowId = e.Element(ns + "RowId") == null ? 0 : (int)e.Element(ns + "RowId"),
                                                            Price = e.Element(ns + "Price") == null ? decimal.Zero : (decimal)e.Element(ns + "Price"),
                                                            Name = e.Element(ns + "Name") == null ? string.Empty : (string)e.Element(ns + "Name"),
                                                            DiscountRate = e.Element(ns + "DiscountRate") == null ? decimal.Zero : (decimal)e.Element(ns + "DiscountRate"),
                                                            Quantity = e.Element(ns + "Quantity") == null ? decimal.Zero : (decimal)e.Element(ns + "Quantity"),
                                                            Cost = e.Element(ns + "Cost") == null ? decimal.Zero : (decimal)e.Element(ns + "Cost"),
                                                            InPrice = e.Element(ns + "InPrice") == null ? decimal.Zero : (decimal)e.Element(ns + "InPrice"),
                                                            ChangeState = invState,

Open in new window

Karrtik Iyer
Software Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 3 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 3 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004