Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem getting an XML Stream Reader to read XML into dataset

Status
Not open for further replies.

jwarmuth

IS-IT--Management
Sep 22, 2001
151
CA
Okee, following the MS documentation trying to get this to work, but am having an issue with it not actually reading or loading the XML.

To begin, we start with a string (glb_returnedXML) which equates to:

Code:
<StockQuotes><Stock><Symbol>INTC</Symbol><Last>24.10</Last><Date>2/28/2005</Date><Time>2:56pm</Time><Change>+0.01</Change><Open>24.15</Open><High>24.49</High><Low>23.86</Low><Volume>63227088</Volume><MktCap>150.1B</MktCap><PreviousClose>24.09</PreviousClose><PercentageChange>+0.04%</PercentageChange><AnnRange>19.64 - 30.14</AnnRange><Earns>1.16</Earns><P-E>20.77</P-E><Name>INTEL CP</Name></Stock></StockQuotes>

I then attemp to read that string via the stream reader like this:

Code:
                Dim ds_formattedXML As DataSet = New DataSet
                Dim dt_formattedXML As DataTable = New DataTable("stockQuote")
                dt_formattedXML.Columns.Add("symbol", Type.GetType("System.String"))
                dt_formattedXML.Columns.Add("last", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("date", Type.GetType("System.DateTime"))
                dt_formattedXML.Columns.Add("time", Type.GetType("System.DateTime"))
                dt_formattedXML.Columns.Add("change", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("open", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("high", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("low", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("volume", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("mktcap", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("previousClose", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("percentageChange", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("annRangeUpper", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("annRangeLower", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("earns", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("pe", Type.GetType("System.Decimal"))
                dt_formattedXML.Columns.Add("name", Type.GetType("System.String"))

                ds_formattedXML.Tables.Add(dt_formattedXML)

                Dim xmlSR As System.IO.StringReader = New System.IO.StringReader(glb_returnedXML)
                ds_formattedXML.ReadXml(xmlSR, XmlReadMode.IgnoreSchema)


After that little bit of code runs, if I query (command window) the value of xmlSR it returns:

Code:
?xmlsr
{System.IO.StringReader}
    Null: {System.IO.TextReader.NullTextReader}
?xmlsr.ReadToEnd.ToString
""

It doesn't throw an error, it just doesn't seem to load the data. Anyone see what I'm missing or doing wrong?!

I do believe this is centric to the reading of the XML string.

Jeff W.
MCSE, CNE
 
Try creating a Stongly Typed Dataset. Put the XML into an XML file. Get focus on the XML code, right-click and select Create Schema. Get focus on the created Schema Code, right-click and select Generate Dataset. You may need "show All Files" To see the created Dataset code.

Compare Code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top