The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 2 of 2

Thread: Need help with xml

  1. #1

    Need help with xml

    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.
    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
    XmlDocument doc;
    DataSet ds = newDataSet();
    int i;

    XmlDocument objFormattedXML = null;
    for (i = 0; i <= (ds.Tables[0].Rows.Count - 1); i++)
    objFormattedXML =
    XmlDeclaration objDeclare = objFormattedXML.CreateXmlDeclaration("1.0", null, null);
    objDeclare = (
    XmlDeclaration)objFormattedXML.InsertBefore(objDeclare, objFormattedXML.DocumentElement);
    XmlElement objRoot = (XmlElement)objFormattedXML.CreateNode(XmlNodeType.Element, "Members", "");

    objRoot = (XmlElement)objFormattedXML.InsertAfter(objRoot, objDeclare);

    XmlNodeList Objective;
    doc =
    Objective = doc.SelectNodes(
    if (Objective.Count > 0)
    XmlElement Member = (XmlElement)objFormattedXML.CreateNode(XmlNodeType.Element, "Member", "");
    "C:\\test" + i + ".xml");

    I am able to split the files, i am getting three xml files but with the same i missing something here.can some assist me with this

    Advance thanks

  2. #2
    not entirely sure about how to do with with an dataset, but i would do use XmlDocument and XmlNode. Sorry but i am not going to check my work to make sure it works, but this shoudl give you an idea for a very nice solution.

    XmlDocument doc = new XmlDocument();

    XmlElement element1 = doc.SelectSingleNode("/Members/Member[0]");
    XmlDocument SaveDoc1 = new XmlDocument();
    SaveDoc1.Load(new StringReader(element1.Outterxml);

    you can rinse and repeat for the other nodes. What it is doing is going creating a sub set or sub document and then loading it into its own memory space and saving it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012