 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
09-22-2010, 10:50 AM
|
#1 (permalink)
|
|
The Visitor
Join Date: Sep 2010
Posts: 4
Thanks: 0
|
How do i Display XML data with Namespace using XSLT Help
Hi Guys, I'm having some real problems using XSLT to display data from a xml file with namespaces. Could anyone advise what i need to do to display the contents of
<ad:advertisement> title, subTitle, displayUrl </ad:advertisement>
and
<item> title, description, link </item>
Here is the XML file, please help, Thankyou, Lucy
Code:
<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
xmlns="http://blogs.law.harvard.edu/tech/rss"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xAL="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0mc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:mc="http://www.mocomm.co.uk/search/responseextensions"
xmlns:ad="http://a9.com/-/opensearch/extensions/advertisement/1.0/"
xmlns:media="http://video.search.yahoo.com/mrss"
xmlns:georss="http://www.georss.org/georss/10"
xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
-
<channel>
<link>http://www.mocomm.co.uk</link>
<description>Search results for "wallpapers"</description>
<lastBuildDate>Fri, 10 Sep 2010 13:02:56 +01:00</lastBuildDate>
<category domain="mcrating">general</category>
-
<category domain="mctaxonomy">
personalisation/downloads / wallpapers / wallpapers
</category>
<category domain="mcdisplayad">Personalisation, downloads</category>
<openSearch:totalResults>2656621</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>6</openSearch:itemsPerPage>
<openSearch:Query role="request" searchTerms="wallpapers"/>
<openSearch:Query role="mc:context" searchTerms="wallpapers" mc:token="Uj03YjUxNzI4Mi0wMzY5LTmNi0yNDBkMDIyMDRjYzdQsQT0xTg2"/>
<openSearch:Query role="mc:substitution" searchTerms="free wallpapers"/>
-
<mc:adSource>
<mc:market>UK</mc:market>
<mc:pool>other</mc:pool>
<mc:moreResults>false</mc:moreResults>
</mc:adSource>
-
<ad:advertisement>
<ad:title>Cute Pooch Cleans Phone Screen, Adorable</ad:title>
<ad:subTitle>Pooch Licks Phone.</ad:subTitle>
<ad:displayUrl>moble.mobi</ad:displayUrl>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/A/1
</link>
</ad:advertisement>
-
<ad:advertisement>
<ad:title>Blah Blah Phone</ad:title>
<ad:subTitle> Phonefun stuff.</ad:subTitle>
<ad:displayUrl>mobzz.mobi</ad:displayUrl>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d7878204cc4/A/2
</link>
</ad:advertisement>
<item>
<title>Free Mobile Wallpaper</title>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/M/2
</link>
<description>Download any of these wallpaper backgrounds for...</description>
<mc:resultType>M</mc:resultType>
<mc:displayUrl>wap.gambile.co.uk</mc:displayUrl>
</item>
-
<item>
<title>Top 3 Realtones</title>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/M/3
</link>
<description>... Videos - Video Download Music - Colour...</description>
<mc:resultType>M</mc:resultType>
<mc:displayUrl>wap.jacksa.co.uk</mc:displayUrl>
</item>
-
<item>
<title>WAP Dowloads</title>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/M/4
</link>
<description>Get mp3 ringtones, games, mobile videos,...</description>
<mc:resultType>M</mc:resultType>
<mc:displayUrl>downwap.com</mc:displayUrl>
</item>
-
<item>
<title>Wallpapers</title>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/M/5
</link>
<description>... and images - Pac Man - Top Ten - Hot...</description>
<mc:resultType>M</mc:resultType>
<mc:displayUrl>downl.co.uk</mc:displayUrl>
</item>
-
<item>
<title>Mp3-Ringtones.Mobi</title>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/M/6
</link>
<description>Get free downloads, ringtones, wallpapers,...</description>
<mc:resultType>M</mc:resultType>
<mc:displayUrl>www.mpones.mobi</mc:displayUrl>
</item>
-
<item>
<title>Cartoonscape</title>
-
<link>
http://www.moton.com/w/cp/7b517282-0369-4665-8df6-240d02204cc4/M/7
</link>
<description>Get free cartoons, movie clips, wallpapers,...</description>
<mc:resultType>M</mc:resultType>
<mc:displayUrl>scape.com</mc:displayUrl>
</item>
</channel>
</rss>
|
|
|
|
09-22-2010, 02:33 PM
|
#2 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
What have you written so far that's failing?
|
|
|
|
09-22-2010, 03:18 PM
|
#3 (permalink)
|
|
The Visitor
Join Date: Sep 2010
Posts: 4
Thanks: 0
|
Sorry this is the php i am using, but i cannot echo the <ad:advertisement> info on the page, please help.
Code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://domaintofile.com/search/file.xml');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data);
foreach($xml->channel as $post) {
//Use namespace, this works
$namespaces = $post->getNameSpaces(true);
$openSearch = $post->children($namespaces['openSearch']);
echo "total results $openSearch->totalResults"; echo "<br/>";
echo " Start Index $openSearch->startIndex"; echo "<br/>";
echo "Items Per Page $openSearch->itemsPerPage"; echo "<br/><br/>";
}
//This bit will not show the title, subTitle or displayUrl for <ad:advertisement>
foreach($xml->channel as $post) {
//Use namespace
$ad = $post->children("http://a9.com/-/opensearch/extensions/advertisement/1.0/");
echo $ad->title;
echo $ad->subTitle;
echo $ad->displayUrl;
}
foreach($xml->channel->item as $post) {
printf('<div class="title_link">Visit <a href="%s">%s</a><br /></div>' . "\n", $post->link, $post->title);
echo "<div class='description'>$post->description </div>";
//Use the namespace
$namespaces = $post->getNameSpaces(true);
$mc = $post->children($namespaces['mc']);
echo $mc->displayUrl;
echo "<br/><br/>";
}
?>
|
|
|
|
09-22-2010, 07:28 PM
|
#4 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
|
Hi Lucy, welcome to TalkPHP.
Just a quicky question before trying to help out, are you wanting to use an XSL template (like in the other thread that you posted in) or to continue using SimpleXML like in your code above?
|
|
|
|
09-22-2010, 08:42 PM
|
#5 (permalink)
|
|
The Visitor
Join Date: Sep 2010
Posts: 4
Thanks: 0
|
Hi salathe,
To be honest i dont mind which way, i've been trying everything for 3 days now and followed dozens of tutorials, i'm pretty lost, i really hope you can help me.
Please feel free to show me anyway that will work, i just want to be able to display the <ad:advertisement> data and the <item> data on a page.
Thankyou, Lucy
|
|
|
|
09-27-2010, 09:55 AM
|
#6 (permalink)
|
|
The Visitor
Join Date: Sep 2010
Posts: 4
Thanks: 0
|
Can you not help either?
Lucy
|
|
|
|
09-27-2010, 06:44 PM
|
#7 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
|
Hi Lucy, sorry for missing this thread!
You were very nearly there with your code above, just a couple of things were a bit strange. Below is some code which is very similar to yours but doesn't output anything; it's just to show how to access the information that you're looking for.
Any questions about what it does differently, and why, just shout.
PHP Code:
// Search results statistics
// No need to loop here, there is only ever
// one block of openSearch numbers
$opensearch = $xml->channel->children('openSearch', TRUE);
$total = $opensearch->totalResults;
$start = $opensearch->startIndex;
$per_page = $opensearch->itemsPerPage;
// Loop over the <ad:advertisement> nodes
foreach ($xml->channel->children('ad', TRUE)->advertisement as $advert) {
$title = $advert->title;
$sub_title = $advert->subTitle;
$disp_url = $advert->displayUrl;
}
// Loop over the <item> nodes, access <mc:displayUrl> nodes
foreach($xml->channel->item as $post) {
$title = $post->title;
$desc = $post->description;
$url = $post->link;
$disp_url = $post->children('mc', TRUE)->displayUrl;
}
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|