开发者

Write an XML-File with LINQ to XML

开发者 https://www.devze.com 2022-12-09 07:55 出处:网络
i`ve got a little problem with LINQ. I read out some information via XML-RPC. Parsing the Method-Response is no problem, but I dont no how to write the

i`ve got a little problem with LINQ. I read out some information via XML-RPC. Parsing the Method-Response is no problem, but I dont no how to write the Data correctly in a new XML-File.

Here`s my Code so far:

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 build a new XML-File which contains all read out conferences (conferenceName) and related participants (displayName)! I got the relation between conferences and displayNames with my query, but dont know how to write this data correctly to a new XML-File, with the format I want... something like this:

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


Use this tool: link text

It helps you to write Xml file with Linq to xml ...in c#


give a try to the PasteXmlAsLinq visual studio add-in, here's the url Visual Studio 2010 Samples for C# 4.0

*PasteXmlAsLinq: A Visual Studio addin that automatically converts XML to LINQ to XML.

0

精彩评论

暂无评论...
验证码 换一张
取 消