有錯誤我已經搜索了類似的問題,但仍然無法弄清楚這一點。XML文檔(2,2)
內部異常:{"<xml xmlns=''> was not expected."}
我拉XML在線來源所以不能進行更改。 http://api.ustream.tv/xml/user/techcrunch/listAllVideos?key=devkey
我使用visual studio 2010從XML生成XSD文件。我使用xsd.exe生成VB類。
這裏是我的所有代碼: Form1中:
Imports System.Xml
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Public Class Form1
Private Const strURL As String = "http://api.ustream.tv/xml/user/techcrunch/listAllVideos?key=devkey"
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Dim ds As New NewDataSet()
Dim myReader As TextReader = New StreamReader("../../listAllVideos.xml")
Dim serializer As New XmlSerializer(GetType(NewDataSet))
ds = DirectCast(serializer.Deserialize(myReader), NewDataSet)
myReader.Close()
End Sub
End Class
listAllVideos.xml:(縮短)
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<results>
<array key="0">
<id>1916735</id>
<title><![CDATA[The TechCrunch Office live 8/2/09 04:50PM]]></title>
<protected>FALSE</protected>
<description><![CDATA[8/2/09 04:50PM PST]]></description>
<createdAt><![CDATA[2009-08-02 16:13:54]]></createdAt>
<rating>3.000</rating>
<lengthInSecond>2146.777</lengthInSecond>
<totalViews>1943</totalViews>
<codecIsForLiveHttp>0</codecIsForLiveHttp>
<serverId>992</serverId>
<videoName><![CDATA[1_170_1249254834012]]></videoName>
<url><![CDATA[http://www.ustream.tv/recorded/1916735]]></url>
<embedTag><![CDATA[<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="320" height="260" id="utv445187" name="utv_n_638715"><param name="flashvars" value="autoplay=false&vid=1916735" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.ustream.tv/flash/viewer.swf" /><embed flashvars="autoplay=false&vid=1916735" width="320" height="260" allowfullscreen="true" allowscriptaccess="always" id="utv445187" name="utv_n_638715" src="http://www.ustream.tv/flash/viewer.swf" type="application/x-shockwave-flash" /></object>]]></embedTag>
<liveHttpUrl><![CDATA[]]></liveHttpUrl>
<imageUrl>
<small><![CDATA[http://static-cdn2.ustream.tv/videopic/0/1/1/1916/1916735/1_170_1916735_120x90_b_1:1.jpg]]></small>
<medium><![CDATA[http://static-cdn2.ustream.tv/videopic/0/1/1/1916/1916735/1_170_1916735_320x240_b_1:1.jpg]]></medium>
</imageUrl>
<sourceChannel>
<id>170</id>
<url><![CDATA[http://www.ustream.tv/channel/170]]></url>
</sourceChannel>
</array>
</results>
<msg><![CDATA[]]></msg>
<error><![CDATA[]]></error>
<processTime>TRUE</processTime>
<version><![CDATA[mashery-r10]]></version>
</xml>
listAllVideos.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="xml">
<xs:complexType>
<xs:sequence>
<xs:element name="results">
<xs:complexType>
<xs:sequence>
<xs:element name="array">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:unsignedInt" />
<xs:element name="title" type="xs:string" />
<xs:element name="protected" type="xs:string" />
<xs:element name="description" type="xs:string" />
<xs:element name="createdAt" type="xs:string" />
<xs:element name="rating" type="xs:decimal" />
<xs:element name="lengthInSecond" type="xs:decimal" />
<xs:element name="totalViews" type="xs:unsignedShort" />
<xs:element name="codecIsForLiveHttp" type="xs:unsignedByte" />
<xs:element name="serverId" type="xs:unsignedShort" />
<xs:element name="videoName" type="xs:string" />
<xs:element name="url" type="xs:string" />
<xs:element name="embedTag" type="xs:string" />
<xs:element name="liveHttpUrl" type="xs:string" />
<xs:element name="imageUrl">
<xs:complexType>
<xs:sequence>
<xs:element name="small" type="xs:string" />
<xs:element name="medium" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sourceChannel">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:unsignedByte" />
<xs:element name="url" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="key" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="msg" type="xs:string" />
<xs:element name="error" type="xs:string" />
<xs:element name="processTime" type="xs:string" />
<xs:element name="version" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
的VB類真的很長,它不會讓我發佈。謝謝你的時間。
Partial Public Class NewDataSet
Inherits Global.System.Data.DataSet
Private tablexml As xmlDataTable
Private tableresults As resultsDataTable
Private tablearray As arrayDataTable
Private tableimageUrl As imageUrlDataTable
Private tablesourceChannel As sourceChannelDataTable
Private relationxml_results As Global.System.Data.DataRelation
Private relationresults_array As Global.System.Data.DataRelation
Private relationarray_imageUrl As Global.System.Data.DataRelation
Private relationarray_sourceChannel As Global.System.Data.DataRelation
Private _schemaSerializationMode As Global.System.Data.SchemaSerializationMode = Global.System.Data.SchemaSerializationMode.IncludeSchema
只發布VB文件的第一位:「Xml」和類以及「NewDataSet」類的定義。 –
我擔心你想把它當作一個DataSet。 –
John的xsd.exe工具生成了一個包含數據集的類。XML比我發佈的要大得多。你可以在這裏看到XML:http://api.ustream.tv/xml/user/techcrunch/listAllVideos?key=devkey –