473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem in Bulk Uploading of XML data?

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.
Jul 3 '06 #1
3 1164
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[i] 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 (wa****@online.microsoft.com, 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.

Jul 4 '06 #2
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[i] 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 (wa****@online.microsoft.com, 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
Jul 5 '06 #3
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 (wa****@online.microsoft.com, 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.

Jul 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
Any help would be appreciated. I am running a script that does the following in succession. 1-Drop existing database and create new database 2-Defines tables, stored procedures and functions...
3
by: Robert K | last post by:
Hello, I have problem: My *.txt file is like it: " 12345612345678123 abcdefabcdefghabc " etc.
2
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. ...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
0
by: Kiran | last post by:
Hi, Does some one here know how to trigger export(bulk/non bulk) and use bulk import without having to manually edit the Xsd file before import. BTW I am assuming that XML is the correct choice...
1
by: SteveH | last post by:
Attempting to use BULK INSERT to transfer data from a csv to a table in a dbo on an instance of sqlServer (MSDE). I’m very new at both sql server & vb.net. I keep getting an error Unexpected...
3
by: Ddraig | last post by:
Howdy, I've spent a good 2 or 3 hours this morning trying to figure out this code. I'm new to the .Net environment and have some VB6 skills but that was 3 years ago. My project I'm working on...
11
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.