HI experts,
I have one question related with xml.i have an xml file of this format.Members being the root element and three elements by name member.Each member will having different child elements and attributes as well.
<Members>
<member>
</member>
<member>
</member>
<member>
</member>
</Members>
I need to split each member element tag to another xml file and save the xml file to hard disk.
Here is the code snippet i have been working on
[SIZE=2][/SIZE][SIZE=2][COLOR=#008080]XmlDocument[/COLOR][/SIZE][SIZE=2] doc;
[/SIZE][SIZE=2][COLOR=#008080]DataSet[/COLOR][/SIZE][SIZE=2] ds = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]DataSet[/COLOR][/SIZE]SIZE=2;
ds.ReadXml(Server.MapPath([/SIZE][SIZE=2][COLOR=#800000]“Members.xml”[/COLOR][/SIZE][SIZE=2]));
[/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i;
[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008080]XmlDocument[/COLOR][/SIZE][SIZE=2] objFormattedXML = [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2] (i = 0; i <= (ds.Tables[0].Rows.Count - 1); i++)
{
objFormattedXML = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]XmlDocument[/COLOR][/SIZE]SIZE=2;
[/SIZE][SIZE=2][COLOR=#008080]XmlDeclaration[/COLOR][/SIZE][SIZE=2] objDeclare = objFormattedXML.CreateXmlDeclaration([/SIZE][SIZE=2][COLOR=#800000]“1.0”[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2]);
objDeclare = ([/SIZE][SIZE=2][COLOR=#008080]XmlDeclaration[/COLOR][/SIZE][SIZE=2])objFormattedXML.InsertBefore(objDeclare, objFormattedXML.DocumentElement);
[/SIZE][SIZE=2][COLOR=#008080]XmlElement[/COLOR][/SIZE][SIZE=2] objRoot = ([/SIZE][SIZE=2][COLOR=#008080]XmlElement[/COLOR][/SIZE][SIZE=2])objFormattedXML.CreateNode([/SIZE][SIZE=2][COLOR=#008080]XmlNodeType[/COLOR][/SIZE][SIZE=2].Element, [/SIZE][SIZE=2][COLOR=#800000]“Members”[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2]objRoot = ([/SIZE][SIZE=2][COLOR=#008080]XmlElement[/COLOR][/SIZE][SIZE=2])objFormattedXML.InsertAfter(objRoot, objDeclare);
[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008080]XmlNodeList[/COLOR][/SIZE][SIZE=2] Objective;
doc = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]XmlDocument[/COLOR][/SIZE]SIZE=2;
doc.Load([/SIZE][SIZE=2][COLOR=#800000]@“c:\Data\Members.xml”[/COLOR][/SIZE][SIZE=2]);
Objective = doc.SelectNodes([/SIZE][SIZE=2][COLOR=#800000]“Members/Member”[/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (Objective.Count > 0)
{
[/SIZE][SIZE=2][COLOR=#008080]XmlElement[/COLOR][/SIZE][SIZE=2] Member = ([/SIZE][SIZE=2][COLOR=#008080]XmlElement[/COLOR][/SIZE][SIZE=2])objFormattedXML.CreateNode([/SIZE][SIZE=2][COLOR=#008080]XmlNodeType[/COLOR][/SIZE][SIZE=2].Element, [/SIZE][SIZE=2][COLOR=#800000]“Member”[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2]);
[SIZE=2]objRoot.AppendChild(Member).InnerXml=Objective[0].InnerXml;
[/SIZE]}
objFormattedXML.Save([/SIZE][SIZE=2][COLOR=#800000]“C:\ est”[/COLOR][/SIZE][SIZE=2] + i + [/SIZE][SIZE=2][COLOR=#800000]".xml"[/COLOR][/SIZE][SIZE=2]);
}
I am able to split the files, i am getting three xml files but with the same data.am i missing something here.can some assist me with this
Advance thanks
[/SIZE]