Avatar of Bran-Damage
Bran-Damage
Flag for United States of America asked on

Trying to add XElements to my existing XML

Here is my XML:

<PWCScript Version="2011113">
  <Table Name="QD" Action="Edit">
    <Choose Name="QD_JOB_NUM" Value="10244" />
    <Choose Name="QD_DES_SEQ" Value="1" />
    <Update Name="QD_DELIV_DATE" Value="01010001" />
    <Update Name="QD_DELIV_METH" Value="UPS Blue" />
    <Update Name="QD_CONSIGN" Value="571081ce-2c62-46f1-b21a-68ad7b52a984" />
    <Update Name="QD_FREIGHT_COST" Value="10.18" />
    <Update Name="QD_PACK_NUM" Value="10244:1" />
    <Update Name="QD_DES_QTY" Value="500" />
    <Update Name="QD_PART_FINAL" Value="QDG_PARTIAL_NONREPREDESP" />
  </Table>
</PWCScript>

I am trying to do this:
xeShipmentXML.Element("PWCScript").Element("Table").Add(CreatePackageXML(ec));

I get an object reference error.

I do a quick watch to see what is causing it:
?xeShipmentXML.Element("PWCScript")

That is returning Null.

I can't seem to figure out what I am doing wrong.  Any help would be appreciated.

Thanks,

Brandon
.NET ProgrammingXMLC#

Avatar of undefined
Last Comment
Bran-Damage

8/22/2022 - Mon
Avodah

Bran-Damage

ASKER
I'm not really seeing the solution for the problem that I am running into.  I have multiple elements with multiple attributes.
ASKER CERTIFIED SOLUTION
Bran-Damage

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
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.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Avodah

Yes as that is the root node.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
santanu30in

Hi

You can do this in two ways

if "ec" is an XElement then you write

xeShipmentXML.Add(ec));

if "ec" is an XML string then you need to write

xeShipmentXML.Add(XElement.Parse(ec));

.net handle all arrange the elements

Thanks
Bran-Damage

ASKER
I figured out my own answer.