New Message on dotNET User Group Hyd

Inserting XML Nodes in a XML Document

Reply
  Reply to Sender   Recommend Message 1 in Discussion
From: Arun Raj.C

Dear Friends,

 

I have two XML documents as follows:

 

1. Order.xml
- <order>

- <purchase>

  <item quantity="1">Def Leppard: Pyromania</item>

  <item quantity="1">Ozzy Osbourne: Goodbye to Romance</item>

  </purchase>

- <shipping>

  <to>Shawn Farkas</to>

  <street>5 21st Street</street>

  <city>Seattle</city>

  <state>WA</state>

  <zip>98000</zip>

  </shipping>

- <payment>

  <card type="visa">0000-0000-0000-0000</card>

  <address sameAsShipping="yes" />

  </payment>

  </order>

 

  1. Address.xml

- <Address>

  <StreetName>Sterling Rd, 1st Cross Street</StreetName>

  <City>Chennai</City>

  <Pincode>600034</Pincode>

  <State>Tamilnadu</State>

  <Country>IN</Country>

  </Address>

 

 

I need to insert all the nodes in Address.xml in Order.xml before node <Shipping>. I tried with the following code but it returns me the following exception.

 

“The reference node is not a child of this node.”

 

Please help me in solving this problem

 

Kind Regards

 

Arun Raj.C

 

The code is as follows

 

using System;

using System.Xml;

using System.Xml.XPath;

 

      public class clsConstruct

      {

            public void ConstructXML()

            {

                  XmlDocument docLocal = new XmlDocument();

                  docLocal.Load("order.xml");

 

                  XmlDocument docAddress = new XmlDocument();

                  docAddress.Load("address.xml");

 

                  XmlNode nodShipping = docLocal.SelectSingleNode("/order/shipping");

 

                  docLocal.InsertBefore(docAddress.DocumentElement, nodShipping);

 

                  docLocal.Save("orderaddress.xml");

 

                  docLocal = null;

                  docAddress = null;

                  nodShipping = null;

            }

 

            public static void Main(string[] args)

            {

                  clsConstruct objClass = new clsConstruct();

                  objClass.ConstructXML();

                  objClass = null;

            }

      }

 


View other groups in this category.


Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to