Finally my requirement is concatenate xml. Furthermore i dont want to Create again element of second method in first method i need to append second method elements in first method
Suppose you have use two string variables to accept the values, you should use XDocument to do the insert and combine the two xml contents together,so please see this:
tahazubairah...
Participant
887 Points
799 Posts
How to append xml element in existing xml doc using c# class
Jul 31, 2012 06:00 AM|LINK
Hi i have a two methods, both create xml using System.XML namespace.
First method retunrn xml like this
Second method retunrn xml like this
Finally my requirement is concatenate xml. Furthermore i dont want to Create again element of second method in first method i need to append second method elements in first method
Taha Zubair Ahmed
http://www.tahazubair.blogspot.com
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to append xml element in existing xml doc using c# class
Aug 01, 2012 06:27 AM|LINK
Hi,
Suppose you have use two string variables to accept the values, you should use XDocument to do the insert and combine the two xml contents together,so please see this:
string xml1 = "<university><college><collname>abc</collname><address>dec</address></college></university>"; string xml2 = "<student><name>rama</name><edu>mca</edu></student>"; XDocument doc = XDocument.Parse(xml1); XElement ele = XElement.Parse(xml2); doc.Document.Descendants("college").FirstOrDefault().AddAfterSelf(ele); doc.Save("c:\\try.xml");tahazubairah...
Participant
887 Points
799 Posts
Re: How to append xml element in existing xml doc using c# class
Aug 01, 2012 09:12 AM|LINK
One method create xml1, second method create xml2 and last method mix up with some addtional elments
XML1 -> contains 2 elements.
XML2 -> contains 3 elements.
XML3 -> contains 1 element + (XML1 and XML2 elements)
Final result = XMl3 -> 6 Elements.
Foreach XML there is a different xml document, I don't know how do i mix up them.
Please advice
Taha Zubair Ahmed
http://www.tahazubair.blogspot.com
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to append xml element in existing xml doc using c# class
Aug 01, 2012 09:14 AM|LINK
Please see my above example, have you run it?It works well with me!
tahazubairah...
Participant
887 Points
799 Posts
Re: How to append xml element in existing xml doc using c# class
Aug 01, 2012 04:40 PM|LINK
First i use system.xml instead of LINQ.Xml namespace
Second the method which use in Method2 want to append in Method1 used same XML Document, is it is necessary used the same XML Document
i doing some thing like this
public XmlElement createTransferRequest() { //XmlDocument xdHeadera = new XmlDocument(); string nSpace = "http://schemas.xmlsoap.org/soap/envelope/"; XmlElement xeHeadera = xdHeadera.CreateElement("S", "Envelope", nSpace); XmlElement xeHeaderb = xdHeadera.CreateElement("S", "Header", nSpace); XmlElement xeHeaderc = createTransferRequestHeader(); xeHeaderb.AppendChild(xeHeaderc); xeHeadera.AppendChild(xeHeaderb); return xeHeadera; }Taha Zubair Ahmed
http://www.tahazubair.blogspot.com
tahazubairah...
Participant
887 Points
799 Posts
Re: How to append xml element in existing xml doc using c# class
Aug 01, 2012 07:47 PM|LINK
Thank you for your reply i simply call the xml1 method in xml1, make the XMLDocument one time only for all of the three (03) methods
XmlDocument xdHeadera = new XmlDocument(); public XmlElement Method1() { //XmlElement creates here... } public XmlElement Method2() { //XmlElement creates here... } public XmlElement MethodFinal() { XmlElement xeHeaderd = (XmlElement)Method1(); xeHeaderb.AppendChild(xeHeaderd); XmlElement xeHeadere = (XmlElement)Method2(); xeHeaderb.AppendChild(xeHeadere); }Taha Zubair Ahmed
http://www.tahazubair.blogspot.com