Reputation: 12748
How can I deserialize an xml with multiple namespace?
I'm pulling the xml from youtube: https://gdata.youtube.com/feeds/api/users/OnlyChillstep?v=2
I can get the < title>, < summary>, but not the < yt:location>
Here's the class, I also tried to put ElementName:="yt:location" with no success
<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)
Upvotes: 1
Views: 1096
Reputation: 2554
"yt:location" means that you'll have to include the namespace aliased by 'yt' in your element definition. Have you tried something like this?
<XmlElement(elementname="location" namespace="[yt's URI <- look in the xml for a xmlns:yt=blah]")>
UPDATE From the link, you have these namespaces to contend with:
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'
Upvotes: 2