Writing an XML File with LINQ to XML

I have a little problem with LINQ. I have read some information via XML-RPC. Parsing the response method is not a problem, but I don't know how to write the Data correctly in a new XML file.

Here is my code:

var confs = from x in file.XPathSelectElements("//member[name='conferenceType'][value = 'active']"
                        + "/parent::node()/member[name='conferenceName']")
                    select x;

        XElement root = new XElement("Active-Conferences");

        foreach (XElement xConfs in confs)
        {
            var participants = from p in xConfs.XPathSelectElements("//member[name='conferenceName']" +
                                   "/parent::node()/member[name='displayName']")
                              select p;

            root.Add(new XElement("conferenceName", xConfs.Element("conferenceName").Value)
                + new XElement("displayName").Value);
        }

        root.Save("d:/neu2.xml");

      

I want to create a new XML file containing all read conferences (conference name) and associated attendees (displayName)! I got a link between conferences and displayNames with my request, but I don't know how to write this data correctly to a new XML file, in the format I want ... something like this:

alt text http://www3.pic-upload.de/22.10.09/49moeyej2crj.jpg

+2


source to share


2 answers


Use this tool: link text



This will help you write Xml file from Linq to xml ... in C #

+3


source


try visual studio PasteXmlAsLinq, here is url Visual Studio 2010 Examples for C # 4.0



* PasteXmlAsLinq: A Visual Studio add-on that automatically converts XML to LINQ to XML.

+1


source







All Articles