Last post Jun 11, 2011 11:44 AM by vipernet
Jun 08, 2011 07:19 PM|vipernet|LINK
Good day all,
I have been working on something that will take large xml File and insert it into SQL. The script First converts it to a CSV file and creates a Datatable then uses Bulkcopy to incret it into SQL.
The issue Im having problems with is miss placed commons within the XML file. I want to search through the XML file and replace the commons with "," before creating the CSV file.
I have been playing with this, but I also read that it wont work very well with large amounts of lines or file sizes
XElement _doc = XElement.Load(@"F:\temp\Test.xml");
new XAttribute(",", ",")
Here is an example line in the XML file.
<English>Scotty's Research Paper, Page 2</English>
I would like the output File to read:
<English>Scotty's Research Paper ,Page 2</English>
That way went I convert it to a CSV File it will read:
Something,Something,Something, Scotty's Research Paper ,Page 2,Something
Something,Something,Something, Scotty's Research Paper, Page2, Something
I can Post Full script if needs be.
Jun 09, 2011 07:55 AM|Steelymar|LINK
XDocument x = XDocument.Parse("<d><a>xxxx,xxx</a><b>xxxx,xx</b></d>");
x = XDocument.Parse(Regex.Replace(x.ToString(), "[,]", "$$#44;"));
Jun 10, 2011 06:08 PM|vipernet|LINK
Thank you for the reply Steelymar
I read up on your sample and Im not really sure how incorrporate it into my script. I also read that it would take a very long time with Large docs. Not sure if the source was correct or not becuase I wasnt able to test it.
How about something like this:
XmlDocument doc = new XmlDocument();
XmlNode root = doc.DocumentElement;
nodelist = root.SelectNodes("decendant::Name[English='A Scrap of Paper, Page']");
foreach (XmlNode comm in nodelist)
nodelist = root.SelectNodes("decendant::Name[English='A Scrap of Paper, Page']");Im getting invalid token or format, any ideas on. Any ideas on the format I would need with SelectNodes?
Jun 11, 2011 08:21 AM|Decker Dong - MSFT|LINK
If you want to replace all the commas with ",", you can try this way:
XDocument doc = XDocument.Load("xxx.xml");
string s = doc.Root.ToString().Replace(",",",");
doc = XDocument.Parse(s);
Jun 11, 2011 11:44 AM|vipernet|LINK
Awesome, Thank you both for your help. I had to change the "," to "%2C". It was giving an error "Invalid syntax for a decimal numeric entity reference" bu works good now. Just have to add something of a Complete or Done when finished to it.
Thanks again :)