Link to home
Start Free TrialLog in
Avatar of Bran-Damage
Bran-DamageFlag 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
Avatar of Avodah
Avodah
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of 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
Avatar of Bran-Damage
Bran-Damage
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes as that is the root node.
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
I figured out my own answer.