Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

What am I doing wrong here? Trying to parse xml into object using linq

$
0
0

I am trying to parse but its not working:

code

Windows.Data.Xml.Dom.XmlDocument _serviceResponse = new Windows.Data.Xml.Dom.XmlDocument(); _serviceResponse.LoadXml(response); System.Xml.Linq.XElement xle = System.Xml.Linq.XElement.Parse(response); //this works and in the intermediate windows this has all the elements correctly parsed. var device = xle.Element("device"); // this is null var iconList = xle.Element("iconList"); // also null var icons = from query in iconList.Descendants("icon") select new Icon { MimeType = (string)query.Element("mimeType"), Url = (string)query.Element("url"), Height = (int)query.Element("height"), Width = (int)query.Element("width"), Depth = (int)query.Element("depth"), }; foreach (Icon icon in icons) {

string path = icon.Url; // collection is empty so never gets here }

the xml is:

<?xml version="1.0" encoding="utf-8"?><root xmlns="urn:schemas-upnp-org:device-1-0"><specVersion><major>1</major><minor>0</minor></specVersion><device><deviceType>urn:schemas-upnp-org:device:MediaServer:1</deviceType><dlna:X_DLNADOC xmlns:dlna="urn:schemas-dlna-org:device-1-0">DMS-1.00</dlna:X_DLNADOC><intel_nmpr:X_INTEL_NMPR xmlns:intel_nmpr="urn:schemas-intel-com:device-1-0">2.0</intel_nmpr:X_INTEL_NMPR><friendlyName>A300: UPnP AV Server</friendlyName><manufacturer>Syabas Technology Sdn Bhd</manufacturer><manufacturerURL>http://www.syabas.com</manufacturerURL><modelDescription>UPnP/AV Media Server</modelDescription><modelName>myiHome Media Server</modelName><modelNumber>1.0</modelNumber><serialNumber>0000001</serialNumber><UDN>uuid:757569643a003a063adc3a833a123a9e</UDN><iconList><icon><mimetype>image/png</mimetype><width>48</width><height>48</height><depth>8</depth><url>/icon/nas_on48.png</url></icon><icon><mimetype>image/png</mimetype><width>120</width><height>120</height><depth>8</depth><url>/icon/nas_on120.png</url></icon><icon><mimetype>image/jpeg</mimetype><width>48</width><height>48</height><depth>24</depth><url>/icon/nas_on48.jpg</url></icon><icon><mimetype>image/jpeg</mimetype><width>120</width><height>120</height><depth>24</depth><url>/icon/nas_on120.jpg</url></icon></iconList><serviceList><service><serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType><serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId><SCPDURL>ConnectionManager/scpd.xml</SCPDURL><controlURL>ConnectionManager/control</controlURL><eventSubURL>ConnectionManager/event</eventSubURL></service><service><serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType><serviceId>urn:upnp-org:serviceId:ContentDirectory</serviceId><SCPDURL>ContentDirectory/scpd.xml</SCPDURL><controlURL>ContentDirectory/control</controlURL><eventSubURL>ContentDirectory/event</eventSubURL></service></serviceList></device></root>


Viewing all articles
Browse latest Browse all 935

Trending Articles