Cannot get Linq to XML query to return results.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am trying to interact with XML returned from Constant Contact that looks like this:
<div style="background-color:white; color:black
<pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue UTF-8<span style="color:black "<span style="color:blue ?>

<span style="color:blue <<span style="color:#a31515 entry <span style="color:red xmlns<span style="color:blue =<span style="color:black "<span style="color:blue http://www.w3.org/2005/Atom<span style="color:black "<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 link <span style="color:red href<span style="color:blue =<span style="color:black "<span style="color:blue /ws/customers/company/contacts/50042<span style="color:black " <span style="color:red rel<span style="color:blue =<span style="color:black "<span style="color:blue edit<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 link<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 id<span style="color:blue >http://api.constantcontact.com/ws/customers/company/contacts/50042<span style="color:blue </<span style="color:#a31515 id<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 title <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue text<span style="color:black "<span style="color:blue >Contact: email@email.com<span style="color:blue </<span style="color:#a31515 title<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 updated<span style="color:blue >2010-10-31T04:55:48.301Z<span style="color:blue </<span style="color:#a31515 updated<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 author<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 name<span style="color:blue >Constant Contact<span style="color:blue </<span style="color:#a31515 name<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 author<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 content <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue application/vnd.ctct+xml<span style="color:black "<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Contact <span style="color:red xmlns<span style="color:blue =<span style="color:black "<span style="color:blue http://ws.constantcontact.com/ns/1.0/<span style="color:black " <span style="color:red id<span style="color:blue =<span style="color:black "<span style="color:blue http://api.constantcontact.com/ws/customers/company/contacts/50042<span style="color:black "<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Status<span style="color:blue >Active<span style="color:blue </<span style="color:#a31515 Status<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 EmailAddress<span style="color:blue >email@email.com<span style="color:blue </<span style="color:#a31515 EmailAddress<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 EmailType<span style="color:blue >HTML<span style="color:blue </<span style="color:#a31515 EmailType<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >John Doe<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 FirstName<span style="color:blue >John<span style="color:blue </<span style="color:#a31515 FirstName<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 MiddleName<span style="color:blue ><span style="color:blue </<span style="color:#a31515 MiddleName<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 LastName<span style="color:blue >Doe<span style="color:blue </<span style="color:#a31515 LastName<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 JobTitle<span style="color:blue ><span style="color:blue </<span style="color:#a31515 JobTitle<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CompanyName<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CompanyName<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 HomePhone<span style="color:blue ><span style="color:blue </<span style="color:#a31515 HomePhone<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 WorkPhone<span style="color:blue ><span style="color:blue </<span style="color:#a31515 WorkPhone<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Addr1<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Addr1<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Addr2<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Addr2<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Addr3<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Addr3<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 City<span style="color:blue ><span style="color:blue </<span style="color:#a31515 City<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 StateCode<span style="color:blue ><span style="color:blue </<span style="color:#a31515 StateCode<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 StateName<span style="color:blue ><span style="color:blue </<span style="color:#a31515 StateName<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CountryCode<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CountryCode<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CountryName<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CountryName<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 PostalCode<span style="color:blue ><span style="color:blue </<span style="color:#a31515 PostalCode<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 SubPostalCode<span style="color:blue ><span style="color:blue </<span style="color:#a31515 SubPostalCode<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Note<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Note<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField1<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField1<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField2<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField2<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField3<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField3<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField4<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField4<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField5<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField5<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField6<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField6<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField7<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField7<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField8<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField8<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField9<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField9<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField10<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField10<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField11<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField11<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField12<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField12<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField13<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField13<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField14<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField14<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 CustomField15<span style="color:blue ><span style="color:blue </<span style="color:#a31515 CustomField15<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 ContactLists<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 ContactList <span style="color:red id<span style="color:blue =<span style="color:black "<span style="color:blue http://api.constantcontact.com/ws/customers/company/lists/5<span style="color:black "<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 link <span style="color:red xmlns<span style="color:blue =<span style="color:black "<span style="color:blue http://www.w3.org/2005/Atom<span style="color:black " <span style="color:red href<span style="color:blue =<span style="color:black "<span style="color:blue /ws/customers/company/lists/5<span style="color:black " <span style="color:red rel<span style="color:blue =<span style="color:black "<span style="color:blue self<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 link<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 OptInSource<span style="color:blue >ACTION_BY_CUSTOMER<span style="color:blue </<span style="color:#a31515 OptInSource<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 OptInTime<span style="color:blue >2010-10-31T04:53:57.939Z<span style="color:blue </<span style="color:#a31515 OptInTime<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 ContactList<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 ContactLists<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 Confirmed<span style="color:blue >true<span style="color:blue </<span style="color:#a31515 Confirmed<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 InsertTime<span style="color:blue >2010-10-31T04:24:35.903Z<span style="color:blue </<span style="color:#a31515 InsertTime<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 LastUpdateTime<span style="color:blue >2010-10-31T04:55:48.301Z<span style="color:blue </<span style="color:#a31515 LastUpdateTime<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 Contact<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 content<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 source<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 id<span style="color:blue >http://api.constantcontact.com/ws/customers/company/contacts<span style="color:blue </<span style="color:#a31515 id<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 title <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue text<span style="color:black "<span style="color:blue >Contacts for Customer: company<span style="color:blue </<span style="color:#a31515 title<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 link <span style="color:red href<span style="color:blue =<span style="color:black "<span style="color:blue contacts<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 link<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 link <span style="color:red href<span style="color:blue =<span style="color:black "<span style="color:blue contacts<span style="color:black " <span style="color:red rel<span style="color:blue =<span style="color:black "<span style="color:blue self<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 link<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 author<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 name<span style="color:blue >company<span style="color:blue </<span style="color:#a31515 name<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 author<span style="color:blue >

<span style="color:blue <<span style="color:#a31515 updated<span style="color:blue >2010-11-09T06:52:43.907Z<span style="color:blue </<span style="color:#a31515 updated<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 source<span style="color:blue >

<span style="color:blue </<span style="color:#a31515 entry<span style="color:blue >

[/code]

I need to access the <ContactLists> field and grab all of the <ContactList> entries so I can get the ID attribute. There can be multiples of this. So I created code like this just to even read the list and make sure the query is working...but
it never returns any results...only says that the Enumeration Returned No Results:

<div style="background-color:white; color:black
<pre>XDocument contactDetails = XDocument.Parse(detailsXML);

<span style="color:blue var contactLists = <span style="color:blue from contactList <span style="color:blue in contactDetails.Descendants(<span style="color:#a31515 "ContactLists")

<span style="color:blue select contactList.Element(<span style="color:#a31515 "ContactList");



<span style="color:blue foreach (<span style="color:blue var contactListDetails <span style="color:blue in contactLists)

Console.WriteLine(contactListDetails.Attribute(<span style="color:#a31515 "id").Value.ToString());

[/code]

In the code above, detailsXML is a string that contains the XML exactly as you see it in the XML above. Any ideas what I am doing wrong? I have tried everything including adding a where clause (even though I dont need one since this is a single
record that will only return one single list of ContractList entries). I tried also parsing it an XElement but nada. How can I get this to work?

View the full article
 
Back
Top