使用多个命名空间反序列化xml
如何反序列化具有多个命名空间的xml 我正在从youtube上提取xml: 我可以得到使用多个命名空间反序列化xml,xml,vb.net,serialization,namespaces,Xml,Vb.net,Serialization,Namespaces,如何反序列化具有多个命名空间的xml 我正在从youtube上提取xml: 我可以得到,,但不能得到 这是一个类,我还尝试将ElementName:=“yt:location”放在这里,但没有成功 <Xml.Serialization.XmlRoot(elementname:="entry", namespace:="http://www.w3.org/2005/Atom")> _ Public Class YoutubeFeed <XmlElement(Elemen
<Xml.Serialization.XmlRoot(elementname:="entry", namespace:="http://www.w3.org/2005/Atom")> _
Public Class YoutubeFeed
<XmlElement(ElementName:="title")> _
Public title As String
<XmlElement(ElementName:="location")> _
Public location As String
End Class
Dim requestUri2 As String = "https://gdata.youtube.com/feeds/api/users/OnlyChillstep?v=2"
Dim request2 As HttpWebRequest = DirectCast(WebRequest.Create(requestUri2), HttpWebRequest)
Dim resultSet2 As YoutubeFeed
Using response2 As WebResponse = request2.GetResponse()
Using responseStream As Stream = response2.GetResponseStream()
Dim serializer As New XmlSerializer(GetType(YoutubeFeed))
resultSet2 = DirectCast(serializer.Deserialize(responseStream), YoutubeFeed)
End Using
End Using
Console.WriteLine(resultSet2.title)
Console.WriteLine(resultSet2.location)
_
公共类YoutubeFeed
_
作为字符串的公共标题
_
作为字符串的公共位置
末级
Dim requestUri2作为字符串=”https://gdata.youtube.com/feeds/api/users/OnlyChillstep?v=2"
Dim request2作为HttpWebRequest=DirectCast(WebRequest.Create(requestUri2),HttpWebRequest)
当YoutubeFeed时,Dim结果2
使用response2作为WebResponse=request2.GetResponse()
使用responseStream作为Stream=response2.GetResponseStream()
Dim序列化程序作为新的XmlSerializer(GetType(YoutubeFeed))
resultSet2=DirectCast(序列化程序.反序列化(responseStream),YoutubeFeed)
终端使用
终端使用
Console.WriteLine(resultSet2.title)
Console.WriteLine(resultSet2.location)
“yt:location”意味着您必须在元素定义中包含别名为“yt”的名称空间。你试过这样的东西吗
<XmlElement(elementname="location" namespace="[yt's URI <- look in the xml for a xmlns:yt=blah]")>
xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:yt='http://gdata.youtube.com/schemas/2007'