Link to home
Start Free TrialLog in
Avatar of adworldmedia
adworldmediaFlag for United States of America

asked on

Parse XML in Linq C#

I've been trying to use the Linq to XML XDocument and Descendants to parse the following XML results; but I'm not having any luck....

I want to be able to extract the ClickURL as well as the title and description...

Any help would be appreciated!!!
<?xml version="1.0" encoding="UTF-8" ?> 
- <Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://dtd.overture.com/schema/affiliate/2.9.3/OvertureSearchResults.xsd">
- <ResultSet id="searchResults" numResults="4" adultRating="X">
- <Listing rank="1" title="Women Photo Personals" description="1000s of Women Flirting. Connect with Local Women!" siteHost="bookofmatches.com" adultRating="X">
  <ClickUrl type="body">http://0.r.msn.com/</ClickUrl> 
  </Listing>
- <Listing rank="2" title="Free Porn Sites" description="Don't spend money on porn! Find a huge list of free porn sites here." siteHost="FreePornJerk.com" adultRating="X">
  <ClickUrl type="body">http://0.r.msn.com/</ClickUrl> 
  </Listing>
- <Listing rank="3" title="No Strings Sex" description="Seeking a One Night Stand? Find People & Hook Up for No Strings Sex." siteHost="NoStringsSex.com" adultRating="X">
  <ClickUrl type="body">http://0.r.msn.com/</ClickUrl> 
  </Listing>
- <Listing rank="4" title="Meet for Sex" description="Looking for Naughty Fun? Meet Hot Locals for Sex!" siteHost="SexMatch.com" adultRating="X">
  <ClickUrl type="body">http://0.r.msn.com/</ClickUrl> 
  </Listing>
  <NextArgs>Keywords=sex&xargs=12KPjg1oZ&hData=12KPjg1o1g4MeKx8rccb%2D8OZeKwi</NextArgs> 
  </ResultSet>
  </Results>

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

I don't think I want to ask why those particular results are the ones you posted as your sample data  ; )

You're going to have problems using XDocument and such with that document because you have some un-encoded ampersands in the data. For example:

...Find People & Hook...
...Keywords=sex&xargs...
...args=12KPjg1oZ&hData...
P.S.

An encoded ampersand should look like:
&amp;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fascinating. Load() didn't like the ampersands, but Parse() seems to be OK with them.