XML Formatted
<status>
<webresponse>
<properties>
<props>
<imghandle>
<image handle=1234>
<imagetag>somewhere</imagetag>
</image>
</imghandle>
</props>
<props>
<imghandle>
<image handle=1235>
<imagetag>somewhere1</imagetag>
</image>
</imghandle>
</props>
</properties>
</webresponse>
</status>
The above is sample of the xml returned to me by a thrid party. I am trying to use Linq to XMl to build my object and I am trying to navigate to <imghandle>/<image handle=1234>
. I can do it with Xpath but when i do the following, I get object ref not set error
from c in searchXMLResult.Descendants("props")
select c.Element("imghandle").Element("image").Attribute("handle");
PS: I know my xml is not formatted well for readability, how does one place XML sections when asking a question here?
Update 1: So after much irritating the 3rd party, I finally get an answer saying that the data i was consuming was outdated and they gave me the new formatted data which lookis like this
<status>
<webresponse>
<properties>
<props>
<imghandle>
<image handle="1234">
<imagetag>somewhere</imagetag>
</image>
</imghandle>
<owner>
<image handle="ABcf">
</image>
</owner>
</props>
</properties>
</webresponse>
</status>
I tried Kevin Thige's suggestion, look at the user suggestions below, and i get an object ref error. Can not having the same element under 2 different sections not work with Linq to XML? i.e
from c in searchXMLResult.Descendants("props")
select c.Element("imghandle").Element("image").Attribute("handle");
and/or
from c in searchXMLResult.Descendants("props")
select c.Element("owner").Element("image").Attribute("handle")
Update2: This is the xml that I am getting and saved to disk
<?xml version="1.0" encoding="utf-8"?>
<status>
<webresponse>
<properties>
<props>
<imghandle>
<image handle="537">
<imagetag>SFO</imagetag>
</image>
</imghandle>
<owner>
<image handle="User-2">
<firstname>
</firstname>
<lastname>Site Administrator</lastname>
<username>admin</username>
</image>
</owner>
<creationdate>2009-03-06T18:07:57Z</creationdate>
<summary>
</summary>
</props>
<status>HTTP/1.1 200 OK</status>
</properties>
</webresponse>
</status>