DataSet.XMLRead not making any tableshttp://forums.asp.net/t/1806842.aspx/1?DataSet+XMLRead+not+making+any+tablesWed, 30 May 2012 01:14:53 -040018068424994502http://forums.asp.net/p/1806842/4994502.aspx/1?DataSet+XMLRead+not+making+any+tablesDataSet.XMLRead not making any tables <p>Hi all,</p> <p>I'm trying to turn the xml below into a dataset / datatable so I can display it in a gridview but it's returning 0 tables?&nbsp; Anythoughts?</p> <pre class="prettyprint">&lt;configuration&gt; &lt;system&gt; &lt;login&gt; &lt;user&gt; &lt;name&gt;joeuser&lt;/name&gt; &lt;uid&gt;2001&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt; &lt;encrypted-password&gt;askldjfc;acmealsiefja;flcnsdlkm&lt;/encrypted-password&gt; &lt;/authentication&gt; &lt;/user&gt; &lt;user&gt; &lt;name&gt;bobuser&lt;/name&gt; &lt;uid&gt;2002&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt; &lt;encrypted-password&gt;askldjfc;acmealsiefja;flcnsdlkm&lt;/encrypted-password&gt; &lt;/authentication&gt; &lt;/user&gt; &lt;user&gt; &lt;name&gt;joeuser&lt;/name&gt; &lt;uid&gt;2002&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt; &lt;encrypted-password&gt;askldjfc;acmealsiefja;flcnsdlkm&lt;/encrypted-password&gt; &lt;/authentication&gt; &lt;/user&gt; &lt;/login&gt; &lt;/system&gt; &lt;/configuration&gt;</pre> <p></p> <pre class="prettyprint"> Dim objXMLSR As System.IO.StringReader = New System.IO.StringReader(xmlResponseString) Dim objDS As New DataSet objDS.ReadXml(objXMLSR, XmlReadMode.IgnoreSchema) gridOutput.DataSource = objDS.Tables("user")</pre> <p></p> 2012-05-23T20:31:46-04:004995604http://forums.asp.net/p/1806842/4995604.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>Try this</p> <pre class="prettyprint">Dim xmlDocument = New XmlDocument() xmlDocument.Load(&quot;Ur xml path&quot;) ' or xmlDocument.LoadXml(xmlResponseString) Dim xmlReader = New XmlNodeReader(xmlDocument) Dim dataSet = New DataSet() dataSet.ReadXml(xmlReader) Dim userTable = dataSet.Tables(&quot;user&quot;)</pre> <p><br> <br> </p> 2012-05-24T11:07:44-04:004995925http://forums.asp.net/p/1806842/4995925.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>Hi,</p> <p></p> <p>Try referencing this code</p> <pre> <b>Dim myDataSet as New DataSet() myDataSet.ReadXml(Server.MapPath(&quot;xyx.xml&quot;))</b> dg.DataSource = myDataSet dg.DataBind()<br><br>Thanks!</pre> 2012-05-24T13:38:40-04:004996534http://forums.asp.net/p/1806842/4996534.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>bluelinenetworks</h4> I'm trying to turn the xml below into a dataset / datatable so I can display it in a gridview but it's returning 0 tables?&nbsp; Anythoughts?</blockquote> <p></p> <p>Hello</p> <p>I think you should simplify your root tag to only oneand you can use DataSet.ReadXml to import the whole xml contents into a DataTable by referring its public property ofDataSet.Tables[0]please check this out</p> <pre class="prettyprint">&lt;configuration&gt; &lt;user&gt; &lt;name&gt;joeuser&lt;/name&gt; &lt;uid&gt;2001&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt;askldjfc;acmealsiefja;flcnsdlkm&lt;/authentication&gt; &lt;/user&gt; &lt;user&gt; &lt;name&gt;bobuser&lt;/name&gt; &lt;uid&gt;2002&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt;your value2&lt;/authentication&gt; &lt;/user&gt; &lt;user&gt; &lt;name&gt;joeuser&lt;/name&gt; &lt;uid&gt;2002&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt;your value3&lt;/authentication&gt; &lt;/user&gt; &lt;/configuration&gt;</pre> <p>And here's your code contents</p> <pre class="prettyprint">DataSet ds = new DataSet() ds.ReadXml("c:\\xxx.xml")</pre> <pre class="prettyprint">'fetch the DataTable instance to be used anyway&hellip;&hellip;</pre> <pre class="prettyprint">ds.Tables(0) </pre> 2012-05-25T01:27:21-04:004996539http://forums.asp.net/p/1806842/4996539.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Ramesh T</h4> <p></p> <p>Try this</p> <pre class="prettyprint">Dim xmlDocument = New XmlDocument() xmlDocument.Load(&quot;Ur xml path&quot;) ' or xmlDocument.LoadXml(xmlResponseString) Dim xmlReader = New XmlNodeReader(xmlDocument) Dim dataSet = New DataSet() dataSet.ReadXml(xmlReader) Dim userTable = dataSet.Tables(&quot;user&quot;)</pre> <p></blockquote></p> <p>Sorry but your answer isn't correct&mdash;&mdash;Have you tried before pasting them outAnd your output cannot output the value of&nbsp;</p> <pre class="prettyprint"><span class="tag">authenticationit's 0</span></pre> <pre class="prettyprint"><span class="tag">The reason is just the xml formation cannot be recognized by the XmlDocument or DataSet directly</span></pre></blockquote> 2012-05-25T01:42:39-04:004996542http://forums.asp.net/p/1806842/4996542.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>Hello Decker</p> <p>Your xml formation doesn't seem rightwould you mind re-formatting them</p> 2012-05-25T01:47:17-04:004996548http://forums.asp.net/p/1806842/4996548.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>TimoYang</h4> <p></p> <p>Hello Decker</p> <p>Your xml formation doesn't seem rightwould you mind re-formatting them</p> <p></p> </blockquote> <p></p> <p>Hi TimoYang</p> <p>My codes have been all well-formattedand here's my codesthe xml contents are also formatted well aboveSo you can check it out</p> <pre class="prettyprint">Module A Public Sub main() Dim xmlDocument = New XmlDocument() xmlDocument.Load(&quot;abc.xml&quot;) Dim xmlReader = New XmlNodeReader(xmlDocument) Dim dataSet = New DataSet() dataSet.ReadXml(xmlReader) Dim userTable = dataSet.Tables(&quot;user&quot;) For Each r As DataRow In userTable.Rows For Each c As DataColumn In userTable.Columns Console.Write(r(c).ToString() &amp; &quot;&lt;===&gt;&quot;) Next Console.WriteLine() Next End Sub End Module</pre> 2012-05-25T02:01:15-04:004996944http://forums.asp.net/p/1806842/4996944.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>@<a title="TimoYang" href="http://forums.asp.net/members/TimoYang.aspx">TimoYang</a></p> <p>Yes, I did check and it works fine.</p> <p>Wat do u mean?, posted xml is a well formed one.</p> <p>can u clarify the below</p> <pre class="prettyprint">authenticationit's 0?</pre> <pre class="prettyprint"><span class="tag"><span class="typ">The</span><span class="pln"> reason </span><span class="kwd">is</span><span class="pln"> just the xml formation cannot be recognized </span><span class="kwd">by</span><span class="pln"> the </span><span class="typ">XmlDocument</span><span class="pln"> </span><span class="kwd">or</span><span class="pln"> </span><span class="typ">DataSet</span><span class="pln"> directly</span><span class="pun">?</span></span></pre> 2012-05-25T08:00:45-04:004996975http://forums.asp.net/p/1806842/4996975.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Ramesh T</h4> Yes, I did check and it works fine.</blockquote> <p></p> <p>RightSo sure</p> <p>Now look at your result</p> <p>joeuser&lt;===&gt;2001&lt;===&gt;xyz&lt;===&gt;0&lt;===&gt;0&lt;===&gt;<br> bobuser&lt;===&gt;2002&lt;===&gt;xyz&lt;===&gt;1&lt;===&gt;0&lt;===&gt;<br> joeuser&lt;===&gt;2002&lt;===&gt;xyz&lt;===&gt;2&lt;===&gt;0&lt;===&gt;</p> <p>Can you see 0</p> <p>And I've do some modifications to the codes from Decker to check your codes</p> <pre class="prettyprint">Module A Public Sub main() Dim xmlDocument = New XmlDocument() xmlDocument.Load(&quot;abc.xml&quot;) ' or xmlDocument.LoadXml(xmlResponseString) Dim xmlReader = New XmlNodeReader(xmlDocument) Dim dataSet = New DataSet() dataSet.ReadXml(xmlReader) Dim userTable = dataSet.Tables(&quot;user&quot;) For Each row As DataRow In userTable.Rows For Each col As DataColumn In userTable.Columns Console.Write(row(col).ToString() &#43; &quot;&lt;===&gt;&quot;) Next Console.WriteLine() Next End Sub End Module</pre> 2012-05-25T08:19:04-04:004997036http://forums.asp.net/p/1806842/4997036.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p><img src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-undecided.gif" alt="Undecided" title="Undecided" class="emoticon" border="0"></p> <p>Sorry Mate, but did u explore the other tables in the dataset(output)?. There is an another table called 'Authentication' in it in which u could find the values/data u r expecting.</p> <p>If u wanna see everything in the 'user' table then u should go with what <a title="Decker Dong - MSFT" href="http://forums.asp.net/members/Decker%20Dong%20-%20MSFT.aspx"> Decker Dong</a> suggested.</p> <p><a title="Decker Dong - MSFT" href="http://forums.asp.net/members/Decker%20Dong%20-%20MSFT.aspx"><br> </a></p> 2012-05-25T08:49:06-04:004997048http://forums.asp.net/p/1806842/4997048.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Ramesh T</h4> <p></p> <p><img src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-undecided.gif" alt="Undecided" title="Undecided" class="emoticon" border="0"></p> <p>Sorry Mate, but did u explore the other tables in the dataset(output)?. There is an another table called 'Authentication' in it in which u could find the values/data u r expecting.</p> <p></p> </blockquote> <p></p> <p>Not at all</p> <p>Plz leave your email and I'll send you one sample</p> 2012-05-25T08:53:46-04:004997057http://forums.asp.net/p/1806842/4997057.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Ramesh T</h4> If u wanna see everything in the 'user' table then u should go with what <a title="Decker Dong - MSFT" href="http://forums.asp.net/members/Decker%20Dong%20-%20MSFT.aspx"> Decker Dong</a> suggested.</blockquote> <p></p> <p>What's does that mean</p> 2012-05-25T08:58:37-04:004998220http://forums.asp.net/p/1806842/4998220.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Ramesh T</h4> Ramesh T</blockquote> <p></p> <p>Wellif possibleplease put all of your complete codes for TimoYangnice contributor</p> <p>Sorry that maybe you have a different kind of way but we cannot understand:( &nbsp;and I copied the TimoYang's sample to have a testthe result isn't actually right:(</p> <p>Probably I've misunderstood youbut plz show us your real codes fully</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>timoYang</h4> timoYang</blockquote> <p></p> <p>I know that you are very careful and want to make contributions to the communitybut plz be kind and patient enough next time-</p> 2012-05-26T01:47:15-04:004999137http://forums.asp.net/p/1806842/4999137.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>Hi Ramesh T,</p> <p>Sorry but to be very honest, your answer isn't rightYour user table doesn't include authentication values, and you've splitted values from xml contents into two tables, that's not what the author wanted!</p> 2012-05-27T08:50:56-04:005002441http://forums.asp.net/p/1806842/5002441.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>@<a title="TimoYang" href="http://forums.asp.net/members/TimoYang.aspx">TimoYang</a></p> <p>I'm afraid, I don't have any other option to achieve this</p> <p>So, u just have 2 options, either</p> <p>- Reformat (simplify) xml as <a title="Decker Dong - MSFT" href="http://forums.asp.net/members/Decker%20Dong%20-%20MSFT.aspx"> Decker Don </a>suggessted (as below) and use the above suggessed code to see everything u expect in a single table ('User') and then bind it to any databound control</p> <pre class="prettyprint">&lt;configuration&gt; &lt;user&gt; &lt;name&gt;joeuser&lt;/name&gt; &lt;uid&gt;2001&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt;askldjfc;acmealsiefja;flcnsdlkm&lt;/authentication&gt; &lt;/user&gt; &lt;user&gt; &lt;name&gt;bobuser&lt;/name&gt; &lt;uid&gt;2002&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt;your value2&lt;/authentication&gt; &lt;/user&gt; &lt;user&gt; &lt;name&gt;joeuser&lt;/name&gt; &lt;uid&gt;2002&lt;/uid&gt; &lt;class&gt;xyz&lt;/class&gt; &lt;authentication&gt;your value3&lt;/authentication&gt; &lt;/user&gt; &lt;/configuration&gt;</pre> <p>- Use the input xml as it is and use the code we suggessted , which will output more than a table (User, Authentication, etc.). U could then construct a new datatable by merging whatever table u want and bind to any databound control. Please note that u have to merge tables manually as these tables have different schemas.<br> <br> </p> <p></p> 2012-05-29T15:23:50-04:005002528http://forums.asp.net/p/1806842/5002528.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p>Hi all,</p> <p>Thanks for the responses.&nbsp; The problem with reformatting the xml is....I have no control over the XML as it comes from a query of a firewall.</p> <p>I'm working on an application that I can query different portions of the configuration.</p> <p>I do have the xsd files for the data, would applying that somehow make this more 'doable'?&nbsp; My concern there is that they are generally 40-50mb in size.</p> 2012-05-29T16:17:06-04:005002937http://forums.asp.net/p/1806842/5002937.aspx/1?Re+DataSet+XMLRead+not+making+any+tablesRe: DataSet.XMLRead not making any tables <p></p> <blockquote><span class="icon-blockquote"></span> <h4>bluelinenetworks</h4> The problem with reformatting the xml is....I have no control over the XML as it comes from a query of a firewall.</blockquote> <p></p> <p>Sorry to hear thatSo</p> <p>1Either do what the contributor Richard's said</p> <p>2Or you can output your whole xml contents into a temporary file and do modifications as what I saidand then Read them into a DataTable</p> 2012-05-30T01:14:53-04:00