Split XML file in C#
Greeting Folks, I have an XML file which have multiple messages in one
large file, my objective it to split the file into singe xml file for each
message, I have a c# code which only gets me the first instance of the
message. can you please tell what am I missing here: Here is my code :
string strSeq;
string strFileName;
XDocument doc = XDocument.Load(@"C:\XMl\MR.xml");
var newDocs = doc.Descendants("Message")
.Select(d => new XDocument(new XElement("FileDump", d)));
foreach (var newDoc in newDocs)
{
strSeq =
XDocument.Load(@"C:\XMl\MR.xml").XPathSelectElement"//FileDump/Message/MsgID").Value;
strFileName = "MR_" + strSeq + ".xml";
newDoc.Save(Console.Out); Console.WriteLine();
newDoc.Save(@"C:\xml\MR\Tst\" + strFileName);
Console.WriteLine();
}
No comments:
Post a Comment