Problem in Bulk Uploading of XML data?

Discussion in 'ASP .Net' started by Sandeep Singh Sekhon, Jul 3, 2006.

  1. Hi
    I am developing an application in ASP.NET 1.1. In this application, I
    want to import the data in bulk from XML Files to the Database. The
    problem is that I want to upload only those nodes which don't have
    errors in it. Rest of the nodes I want to show to the user so that he
    can correct them and upload to the database. How can I do this?

    I m using XmlDocument to separate the nodes having errors but I am not
    able to remove the nodes with errors from the original document. Because
    if I remove any node, it just stops the foreach loop to traverse the
    nodes to find out which one is having error and which one not.
    Is there any way to remove the nodes having error without stopping the
    looping?

    Thanks, I wud be grateful for any help on this topic.
     
    Sandeep Singh Sekhon, Jul 3, 2006
    #1
    1. Advertising

  2. Hi,

    Thank you for your post.

    Based on my understanding, your question is how to remove child nodes from
    xml document without stopping the loop over all child nodes. If I've
    misunderstood anything, please feel free to post here.

    I think other than looping using "foreach", you can use the index to loop
    over all child nodes:

    <?xml version="1.0" encoding="utf-8" ?>
    <root>
    <node id="node1" valid="true"></node>
    <node id="node2" valid="false"></node>
    <node id="node3" valid="true"></node>
    </root>

    XmlDocument doc = new XmlDocument();
    doc.Load(@"..\..\XmlFile1.xml");

    int i = 0;
    while (i < doc.DocumentElement.ChildNodes.Count)
    {
    XmlElement element = doc.DocumentElement.ChildNodes as XmlElement;
    if (element.Attributes["valid"].Value == "false")
    {
    doc.DocumentElement.RemoveChild(element);
    } else
    {
    i++;
    }
    }

    foreach (XmlElement element in doc.DocumentElement.ChildNodes)
    {
    Console.WriteLine(element.Attributes["id"].Value);
    }

    Hope this helps. Please feel free to post here if anything is unclear.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 4, 2006
    #2
    1. Advertising

  3. Walter Wang [MSFT] wrote:
    > Hi,
    >
    > Thank you for your post.
    >
    > Based on my understanding, your question is how to remove child nodes from
    > xml document without stopping the loop over all child nodes. If I've
    > misunderstood anything, please feel free to post here.
    >
    > I think other than looping using "foreach", you can use the index to loop
    > over all child nodes:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    > <root>
    > <node id="node1" valid="true"></node>
    > <node id="node2" valid="false"></node>
    > <node id="node3" valid="true"></node>
    > </root>
    >
    > XmlDocument doc = new XmlDocument();
    > doc.Load(@"..\..\XmlFile1.xml");
    >
    > int i = 0;
    > while (i < doc.DocumentElement.ChildNodes.Count)
    > {
    > XmlElement element = doc.DocumentElement.ChildNodes as XmlElement;
    > if (element.Attributes["valid"].Value == "false")
    > {
    > doc.DocumentElement.RemoveChild(element);
    > } else
    > {
    > i++;
    > }
    > }
    >
    > foreach (XmlElement element in doc.DocumentElement.ChildNodes)
    > {
    > Console.WriteLine(element.Attributes["id"].Value);
    > }
    >
    > Hope this helps. Please feel free to post here if anything is unclear.
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >

    thanks Walter for Your reply
     
    Sandeep Singh Sekhon, Jul 5, 2006
    #3
  4. Hi,

    Appreciate your update and response. If you have any other questions or
    concerns, please do not hesitate to contact us. It is always our pleasure
    to be of assistance.

    Have a nice day!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 6, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sudha Pune

    Bulk data in grid view [ASP.Net]

    Sudha Pune, Feb 24, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    3,005
    Sudha Pune
    Mar 7, 2006
  2. Dung Ping
    Replies:
    10
    Views:
    1,057
    Chaddy2222
    Jan 16, 2006
  3. Niraj
    Replies:
    2
    Views:
    10,838
    Jim Kennedy
    Mar 3, 2004
  4. =?Utf-8?B?YW1qYWQ=?=

    SQL XML Bulk Load 4.0 problem with asp.net 1.1

    =?Utf-8?B?YW1qYWQ=?=, Sep 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    507
    =?Utf-8?B?YW1qYWQ=?=
    Sep 15, 2006
  5. jeet_sen

    Effective way to handle bulk XML file

    jeet_sen, Apr 3, 2006, in forum: Javascript
    Replies:
    3
    Views:
    103
    David Dorward
    Apr 3, 2006
Loading...

Share This Page