Everyone, I'm just goofing off here with some XML. I've got an XML file of Van Halen albums, and I want to take all the album titles and show them in a data grid. I found some code to convert a XmlNodeList to a DataSet, but it is returning with an error of
"System.Web.HttpException: The IListSource does not contain any data sources." Some code:
XML Sample:
5421
Van Halen
4
Hear About It Later
Fair Warning
04:35
Rock
Code:
Dim x As Integer
Dim dstMenu As DataSet
Dim dstAlbumTitles As DataSet
Dim objAlbum As XmlNodeList
Dim objDataDocument As XmlDataDocument
dstMenu = New DataSet()
dstMenu.ReadXml(MapPath("vanhalen.xml"), XmlReadMode.Auto)
objDataDocument = New XmlDataDocument(dstMenu)
objAlbum = objDataDocument.GetElementsByTagName("AlbumTitle")
Dim xNodeList As XmlNodeList = objAlbum
dstAlbumTitles = New DataSet()
Dim xReader As XmlTextReader
For x = 0 To xNodeList.Count - 1
xReader = New XmlTextReader(xNodeList.Item(x).OuterXml, XmlNodeType.Element, New XmlParserContext(Nothing, Nothing, Nothing, XmlSpace.None))
dstAlbumTitles.ReadXml(xReader, XmlReadMode.InferSchema)
Next x
dgrdTitles.DataSource = dstAlbumTitles
dgrdTitles.DataBind()
From what I can tell, the loop is pulling OuterXML from the XMLNodeList, but it can't return anything. Also, does anyone know how to return distinct records in
XML? This is not a life-or-death situation, just goofing. Thanks, Mike
If you are using ASP.NET, then the binding mechanism uses any object that supports IEnumerable. That means that you can bind an XmlNodeList directly to an object as its .DataSource. I posted an example on my web log:
http://weblogs.asp.net/kaevans/posts/9713.aspx.
interdev159
Member
170 Points
35 Posts
XmlNodeList to DataSet
Jul 29, 2003 03:39 PM|LINK
XML Sample: 5421 Van Halen 4 Hear About It Later Fair Warning 04:35 Rock Code: Dim x As Integer Dim dstMenu As DataSet Dim dstAlbumTitles As DataSet Dim objAlbum As XmlNodeList Dim objDataDocument As XmlDataDocument dstMenu = New DataSet() dstMenu.ReadXml(MapPath("vanhalen.xml"), XmlReadMode.Auto) objDataDocument = New XmlDataDocument(dstMenu) objAlbum = objDataDocument.GetElementsByTagName("AlbumTitle") Dim xNodeList As XmlNodeList = objAlbum dstAlbumTitles = New DataSet() Dim xReader As XmlTextReader For x = 0 To xNodeList.Count - 1 xReader = New XmlTextReader(xNodeList.Item(x).OuterXml, XmlNodeType.Element, New XmlParserContext(Nothing, Nothing, Nothing, XmlSpace.None)) dstAlbumTitles.ReadXml(xReader, XmlReadMode.InferSchema) Next x dgrdTitles.DataSource = dstAlbumTitles dgrdTitles.DataBind()From what I can tell, the loop is pulling OuterXML from the XMLNodeList, but it can't return anything. Also, does anyone know how to return distinct records in XML? This is not a life-or-death situation, just goofing. Thanks, MikeReloaded
Member
235 Points
47 Posts
Re: XmlNodeList to DataSet
Jul 30, 2003 02:02 AM|LINK
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: XmlNodeList to DataSet
Aug 06, 2003 08:23 PM|LINK