Connecting Tech Pros Worldwide Forums | Help | Site Map

Parsing the "description" element of rss/xml

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: Oct 2 '09
Hello, I have php code which takes an rss feed and outputs it on a page of my website. For each item it shows the link, title and description.

My problem is the description element contains a lot of information (some links and other stuff) and I want to extract one of the links out of this information, so that on my webpage I am shown the link, title and the link I want out of the description, for every item. How would I achieve this? If no-one knows can anyone point me to books which might know.


Here is the description tag:
Expand|Select|Wrap|Line Numbers
  1. <description>submitted by &lt;a href=&quot;http://www.examplesite.com/user/hoopy001&quot;&gt; hoopy001 &lt;/a&gt; &lt;br/&gt; &lt;a href=&quot;http://www.telegraph.co.uk/earth/wildlife/6187320/Snake-with-foot-found-in-China.html&quot;&gt;[link]&lt;/a&gt; &lt;a href="http://www.examplesite.com/steep/meeic/comments/9feftggfy/snake_with_foot_found_in_china_telegraph/"&gt;[comment]&lt;/a&gt;</description>
In this example I want the link telegraph.co.uk with the word [link] after it, which i bolded out.

Any ideas would be gratefully received.

Thank you

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#2: Oct 3 '09

re: Parsing the "description" element of rss/xml


possibility one
extract all the text content and use PHP to filter the link via RegEx

possibility two
write the html content as such using the xhtml namespace, then you can use XPath to look for the appropriate anchor element.
Reply