StringReader not "reading" given string object
I have a table in a mysql database, where i have stored many XML strings. The XML strings are like this:
<?xml version="1.0" encoding="utf-8"?>
<plant>
<concept>
<item>Payroll</item>
<father>administration</father>
<name>CEO</name>
<total>25000</total>
<week1>21000</week1>
<week2>1000</week2>
<week3>1000</week3>
<week4>1000</week4>
<week5>1000</week5>
<approval>Not Approved</approval>
</concept>
<concept>
<item>Payroll</item>
<father>administration</father>
<name>Cleaning Lady</name>
<total>25000</total>
<week1>21000</week1>
<week2>1000</week2>
<week3>1000</week3>
<week4>1000</week4>
<week5>1000</week5>
<approval>Approved</approval>
</concept>
</plant>
I make a query, like:
select xml from table
and the result, stored in a dataset.
I then load my XML string in a simple string object via a dataset, something like
stringXML = dset.tables(0).rows(0)(0).tostring
and this is where problems begin, i know how to load a dataset from an XMl file with a string reader.
So my usual code goes like:
Dim dset2 As New DataSet
Dim reader As StringReader
reader = New StringReader(xml) 'xml contains the xml string 开发者_运维百科already loaded
dset2.ReadXml(reader)
When I am debugging, the reader (stringReader) does not load a thing!, I have other projects with the same programming methodology and worked perfectly, but now, it doesn't work.
String reader return nothing, and if I add an inspection (vs 2005), it's the same, my var reader has nothing.
Am i skipping something? or just tired...
I can't see what the exact problem is but here's a couple of things you should check.
1- The way you get the string doesn't matter... what is important to look at, it's the value of the "xml" variable when you call this line is executed:
reader = New StringReader(xml) 'xml contains the xml string already loaded
Does xml variable contains the expected value? If it doesn't then check the way you store and retreive the value from the database.
2-Is it the stringReader that doesn't load a thing, or is it the dset2.ReadXml that doesn't load the expected values?
3- How did you determine that "String reader return nothing"? In your case, reader is an object, not a function... It can be null (or nothing in VB), but it cannot return nothing. Have you tried reader.ReadToEnd to find out what was loaded?
精彩评论