I get a larger XML file from an outside source. I would like to read specific elements and write them to a new XML file for my intended user. My user doesn't need the other elements.
I tried this but I don't think I'm navigating the hierarchy correctly.
Let say the XML looks like this:Code:XElement xml = XElement.Load("test.xml"); XElement xml2 = new XElement("applications", new XElement("application", new XElement("uid", xml.Element("uid").Value))); xml2.Save(@"C:\newfile.xml");
And I just want a file like this in the end:Code:<?xml version="1.0" encoding="utf-8"?> <applications> <applicant> <uid>321321321</uid> <address>321321321</address> <phone>321321321</phone> <email>321321321</email> </applicant> </applications>
I also know I need a loop in there somewhere.Code:<?xml version="1.0" encoding="utf-8"?> <applications> <applicant> <uid>321321321</uid> </applicant> </applications>
Any help is appreciated.
Thanks.




Reply With Quote