Я искал похожие вопросы и до сих пор не могу понять это.
Внутреннее исключение: {"<xml xmlns=''> was not expected."}
Я извлекаю XML из онлайн-источника, поэтому не могу внести в него изменения.http://api.ustream.tv/xml/user/techcrunch/listAllVideos?key=devkey
Я сгенерировал XSD-файл из XML с помощью Visual Studio 2010. Я использовал 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