<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>TDD developer &#187; xmlDocument</title>
	<atom:link href="http://testdrivendevelopment.wordpress.com/tag/xmldocument/feed/" rel="self" type="application/rss+xml" />
	<link>http://testdrivendevelopment.wordpress.com</link>
	<description>Diary of an agile developer</description>
	<lastBuildDate>Wed, 28 Oct 2009 22:06:05 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='testdrivendevelopment.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/a6ef45b2d30fa0fcbe697fa111d46fdd?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>TDD developer &#187; xmlDocument</title>
		<link>http://testdrivendevelopment.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://testdrivendevelopment.wordpress.com/osd.xml" title="TDD developer" />
		<item>
		<title>Convert XmlDocument to DataTable using LinqToXml</title>
		<link>http://testdrivendevelopment.wordpress.com/2008/05/03/convert-xmldocument-to-datatable-using-linqtoxml/</link>
		<comments>http://testdrivendevelopment.wordpress.com/2008/05/03/convert-xmldocument-to-datatable-using-linqtoxml/#comments</comments>
		<pubDate>Sat, 03 May 2008 19:21:41 +0000</pubDate>
		<dc:creator>makka</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dataTable]]></category>
		<category><![CDATA[linqToXml]]></category>
		<category><![CDATA[xmlDocument]]></category>

		<guid isPermaLink="false">http://testdrivendevelopment.wordpress.com/2008/05/03/convert-xmldocument-to-datatable-using-linqtoxml/</guid>
		<description><![CDATA[I found this solution to import in my database an XML file received from an external legacy system via a POP3 server. I used an open source library  to get the XML file on my hard disk. Now I need to bulk insert this information into a remote server where I can access only [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=testdrivendevelopment.wordpress.com&blog=2459763&post=18&subd=testdrivendevelopment&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I found this solution to import in my database an XML file received from an external legacy system via a POP3 server. I used an open source library  to get the XML file on my hard disk. Now I need to bulk insert this information into a remote server where I can access only using MSSQL protocol so I dediced to use SqlBulkCopy class. In order to use this class I need to transfor the XML document into a DataTable.</p>
<p>This a sample of my XML file:</p>
<p><code>&lt;sales&gt;<br />
&lt;pos code="000000" index="0000000003"&gt;<br />
&lt;year value="2007"&gt;<br />
&lt;month value="04"&gt;<br />
&lt;day value="02"&gt;<br />
&lt;tipo code="L"&gt;<br />
&lt;row code="002039055" qty="1" price="7.290" /&gt;<br />
&lt;row code="002309045" qty="134" price="2.390" /&gt;<br />
&lt;row code="002427274" qty="21" price="6.500" /&gt;<br />
&lt;row code="003366150" qty="1" price="4.600" /&gt;<br />
&lt;row code="003785045" qty="0.1" price="6.940" /&gt;<br />
&lt;/tipo&gt;<br />
&lt;tipo code="V"&gt;<br />
&lt;row code="002039055" qty="21" price="7.290" /&gt;<br />
&lt;row code="003366150" qty="87" price="4.600" /&gt;<br />
&lt;/tipo&gt;<br />
&lt;/day&gt;<br />
&lt;/month&gt;<br />
&lt;/year&gt;<br />
&lt;/pos&gt;<br />
&lt;/sales&gt;</code></p>
<p>and this the code<br />
<code>XElement xElement = XElement.Load("test.xml");<br />
var elements = from f in xElement.Descendants("riga")<br />
select new<br />
{<br />
Code = f.Attribute("code").Value,<br />
Quantity = f.Attribute("qty").Value,<br />
Price = f.Attribute("price").Value,<br />
Type = f.Parent.Attribute("code").Value,<br />
Day = f.Parent.Parent.Attribute("value").Value,<br />
Month = f.Parent.Parent.Parent.Attribute("value").Value,<br />
Year = f.Parent.Parent.Parent.Parent.Attribute("value").Value,<br />
} ;</code></p>
<p>Now you can build you DataTable using the common syntax</p>
<p><code>DataTable dataTable = new DataTable("dbo.Vendite");<br />
dataTable.Columns.Add("data", typeof(DateTime));<br />
//others columns<br />
</code><br />
and the you can add rows using a foreach loop</p>
<p><code>foreach (var element in elements)<br />
{<br />
DataRow dataRow = dataTable.NewRow();<br />
dataRow["data"] = element.Date;<br />
//others columns<br />
dataTable.Rows.Add(dataRow);<br />
}</code></p>
<p>now I can use SqlBulkCopy to insert data in the server locate inside LAN.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8cef36c5-77c5-45f4-9446-0d5e43e5ca0e" class="wlWriterSmartContent" style="display:inline;margin:0;padding:0;">Technorati Tag: <a rel="tag" href="http://technorati.com/tags/xmlDocument">xmlDocument</a>,<a rel="tag" href="http://technorati.com/tags/linqToXml">linqToXml</a>,<a rel="tag" href="http://technorati.com/tags/dataTable">dataTable</a></div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/testdrivendevelopment.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/testdrivendevelopment.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/testdrivendevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/testdrivendevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/testdrivendevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/testdrivendevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/testdrivendevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/testdrivendevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/testdrivendevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/testdrivendevelopment.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/testdrivendevelopment.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/testdrivendevelopment.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=testdrivendevelopment.wordpress.com&blog=2459763&post=18&subd=testdrivendevelopment&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://testdrivendevelopment.wordpress.com/2008/05/03/convert-xmldocument-to-datatable-using-linqtoxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eaac7e727c1e026a9677bf418eca3ee9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">makka</media:title>
		</media:content>
	</item>
	</channel>
</rss>