<?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/"
	>

<channel>
	<title>S i X h E a D { ? } &#187; XmlDocument</title>
	<atom:link href="http://sixhead.com/tag/xmldocument/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixhead.com</link>
	<description>เมื่อความรู้มีไว้แบ่งปัน</description>
	<lastBuildDate>Mon, 27 Feb 2012 06:23:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>XmlDocument</title>
		<link>http://sixhead.com/2008/04/08/xmldocument/</link>
		<comments>http://sixhead.com/2008/04/08/xmldocument/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 03:46:07 +0000</pubDate>
		<dc:creator>Pipo</dc:creator>
				<category><![CDATA[VB.Net & Aspx]]></category>
		<category><![CDATA[XmlDocument]]></category>

		<guid isPermaLink="false">http://sixhead.com/?p=41</guid>
		<description><![CDATA[Dim myXmlDoc As XmlDocument = New XmlDocument&#40;&#41; 'myXmlDoc.LoadXml(strXml) ' load from string 'myXmlDoc.Load(Server.MapPath(&#34;path/to/xml.xml&#34;)) myXmlDoc.Load&#40;&#34;http://domain/xml.xml&#34;&#41; Dim UserIdNode As XmlNodeList = myXmlDoc.GetElementsByTagName&#40;&#34;UserId&#34;&#41; Dim FirstNameNode As XmlNodeList = myXmlDoc.GetElementsByTagName&#40;&#34;FirstName&#34;&#41; &#160; Dim UserId As String = Convert.ToString&#40;UserIdNode&#40;0&#41;.InnerText&#41; Dim FirstName As String = Convert.ToString&#40;FirstNameNode&#40;0&#41;.InnerText&#41; ลองดึงข้อมูลจาก xml แล้ววน loop XmlDocument.xml &#60;SiXhEaD&#62; &#60;Member&#62; &#60;UserId&#62;6&#60;/UserId&#62; &#60;Zipcode&#62;10000&#60;/Zipcode&#62; &#60;Email&#62;email1@domain.com&#60;/Email&#62; &#60;/Member&#62; &#60;Member&#62; &#60;UserId&#62;7&#60;/UserId&#62; &#60;Zipcode&#62;20000&#60;/Zipcode&#62; &#60;Email&#62;email2@domain.com&#60;/Email&#62; &#60;/Member&#62; [...]]]></description>
			<content:encoded><![CDATA[<pre class="vbnet"><span style="color: #0600FF;">Dim</span> myXmlDoc <span style="color: #FF8000;">As</span> XmlDocument = <span style="color: #FF8000;">New</span> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-style: italic;">'myXmlDoc.LoadXml(strXml) ' load from string</span>
<span style="color: #008080; font-style: italic;">'myXmlDoc.Load(Server.MapPath(&quot;path/to/xml.xml&quot;))</span>
myXmlDoc.<span style="color: #0000FF;">Load</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://domain/xml.xml&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> UserIdNode <span style="color: #FF8000;">As</span> XmlNodeList	=	myXmlDoc.<span style="color: #0000FF;">GetElementsByTagName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;UserId&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> FirstNameNode <span style="color: #FF8000;">As</span> XmlNodeList	=	myXmlDoc.<span style="color: #0000FF;">GetElementsByTagName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;FirstName&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> UserId <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>	=	Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>UserIdNode<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InnerText</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> FirstName <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>	=	Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>FirstNameNode<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InnerText</span><span style="color: #000000;">&#41;</span></pre>
<p><span id="more-41"></span></p>
<p>ลองดึงข้อมูลจาก xml แล้ววน loop</p>
<p>XmlDocument.xml
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;SiXhEaD<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Member<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;UserId<span style="font-weight: bold; color: black;">&gt;</span></span></span>6<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/UserId<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Zipcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>10000<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Zipcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Email<span style="font-weight: bold; color: black;">&gt;</span></span></span>email1@domain.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Member<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Member<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;UserId<span style="font-weight: bold; color: black;">&gt;</span></span></span>7<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/UserId<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Zipcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>20000<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Zipcode<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Email<span style="font-weight: bold; color: black;">&gt;</span></span></span>email2@domain.com<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Member<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Status<span style="font-weight: bold; color: black;">&gt;</span></span></span>Complete<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Status<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/SiXhEaD<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>XmlDocument.aspx
<pre class="vbnet">&lt;%@ Import <span style="color: #0600FF;">Namespace</span>=<span style="color: #808080;">&quot;System.Xml&quot;</span> %&gt;
&lt;%
<span style="color: #0600FF;">Dim</span> myXmlDoc <span style="color: #FF8000;">As</span> XmlDocument = <span style="color: #FF8000;">New</span> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
myXmlDoc.<span style="color: #0000FF;">Load</span><span style="color: #000000;">&#40;</span>Server.<span style="color: #0000FF;">MapPath</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;XmlDocument.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> UserIdNode <span style="color: #FF8000;">As</span> XmlNodeList = myXmlDoc.<span style="color: #0000FF;">GetElementsByTagName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;UserId&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> ZipcodeNode <span style="color: #FF8000;">As</span> XmlNodeList = myXmlDoc.<span style="color: #0000FF;">GetElementsByTagName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Zipcode&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> EmailNode <span style="color: #FF8000;">As</span> XmlNodeList = myXmlDoc.<span style="color: #0000FF;">GetElementsByTagName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Email&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> StatusNode <span style="color: #FF8000;">As</span> XmlNodeList = myXmlDoc.<span style="color: #0000FF;">GetElementsByTagName</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Status&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> UserId <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
<span style="color: #0600FF;">Dim</span> Zipcode <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
<span style="color: #0600FF;">Dim</span> Email <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
<span style="color: #0600FF;">Dim</span> Status <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> strResult <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> = <span style="color: #808080;">&quot;&quot;</span>
&nbsp;
<span style="color: #0600FF;">Dim</span> intI <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span> = <span style="color: #FF0000;">0</span>
<span style="color: #FF8000;">For</span> intI = <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">To</span> UserIdNode.<span style="color: #0000FF;">Count</span> - <span style="color: #FF0000;">1</span>
    UserId = UserIdNode<span style="color: #000000;">&#40;</span>intI<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InnerText</span>
    Zipcode = ZipcodeNode<span style="color: #000000;">&#40;</span>intI<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InnerText</span>
    Email = EmailNode<span style="color: #000000;">&#40;</span>intI<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InnerText</span>
&nbsp;
    strResult = strResult &amp; <span style="color: #808080;">&quot;UserId: &quot;</span> &amp; UserId &amp; <span style="color: #808080;">&quot;&lt;br&gt;&quot;</span>
    strResult = strResult &amp; <span style="color: #808080;">&quot;Zipcode: &quot;</span> &amp; Zipcode &amp; <span style="color: #808080;">&quot;&lt;br&gt;&quot;</span>
    strResult = strResult &amp; <span style="color: #808080;">&quot;Email: &quot;</span> &amp; Email &amp; <span style="color: #808080;">&quot;&lt;br&gt;&quot;</span>
    strResult = strResult &amp; <span style="color: #808080;">&quot;...............&quot;</span> &amp; <span style="color: #808080;">&quot;&lt;br&gt;&quot;</span>
<span style="color: #FF8000;">Next</span>
&nbsp;
Status = StatusNode<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InnerText</span>
strResult = strResult &amp; <span style="color: #808080;">&quot;&quot;</span> &amp; Status &amp; <span style="color: #808080;">&quot;&lt;br&gt;&quot;</span>
&nbsp;
Response.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span>strResult<span style="color: #000000;">&#41;</span>
%&gt;</pre>
<p>ผลลัพท์</p>
<pre>UserId: 6
Zipcode: 10000
Email: email1@domain.com
...............
UserId: 7
Zipcode: 20000
Email: email2@domain.com
...............
Complete</pre>
<p><map name='google_ad_map_41_f21c57aff87a446f'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/41?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_41_f21c57aff87a446f' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=41&amp;url= http%3A%2F%2Fsixhead.com%2F2008%2F04%2F08%2Fxmldocument%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://sixhead.com/2008/04/08/xmldocument/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

