Problem in Bulk Uploading of XML data?

  • Thread starter Sandeep Singh Sekhon
  • Start date
S

Sandeep Singh Sekhon

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.
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
S

Sandeep Singh Sekhon

Walter said:
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 ([email protected], 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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top