saipkjai Posted October 3, 2007 Share Posted October 3, 2007 hi Right now, I'm trying to retrieve the prefix of the name space using the lookupprefix(String url). But somehow, it does not return me anything. Am I miss use the function? the approach that I'm using is $xml = simplexml_load_file($file); then for each of the content , I do $prefix = $entry->content->lookupPrefix('http://www.w3.org/1999/xhtml'); echo "<p>$prefix</p>"; XML sample <content type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <xhtml:div>This is also <xhtml:em>very</xhtml:em> exciting. &</xhtml:div> </content> Am I missing something? thx for the help Quote Link to comment https://forums.phpfreaks.com/topic/71631-solved-namespace-prefix-lookup/ Share on other sites More sharing options...
sKunKbad Posted October 3, 2007 Share Posted October 3, 2007 you will need to declare your namespaces to get to the content you desire. i did it like this: $namespaces = $feed->getNamespaces(true); $content = $feed->channel->item->children($namespaces['content']); The XML: <?xml version="1.0" ?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/"> <channel> <title>Bible Gateway's Verse of the Day</title> <link>http://www.biblegateway.com</link> <description>A daily word of exultation.</description> <dc:language>en-us</dc:language> <dc:creator>BibleGateway.com</dc:creator> <dc:rights>Copyright 2004</dc:rights> <dc:date>2007-10-03T02:27:03Z</dc:date> <sy:updatePeriod>daily</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase> <item> <title>1 Peter 1:3</title> <description>Verse of the day</description> <guid isPermaLink="false">http://www.biblegateway.com/passage/?search=1+Peter+1%3A3&version=31</guid> <content:encoded> <![CDATA[“[Praise to God for a Living Hope] Praise be to the God and Father of our Lord Jesus Christ! In his great mercy he has given us new birth into a living hope through the resurrection of Jesus Christ from the dead,”<br/><br/> Brought to you by <a href="http://www.biblegateway.com">BibleGateway.com</a>. Copyright (C) NIV. All Rights Reserved.]]> </content:encoded> <dc:rights>Powered by BibleGateway.com</dc:rights> <dc:date>2007-10-03T02:27:03Z</dc:date> </item> </channel> </rss> Quote Link to comment https://forums.phpfreaks.com/topic/71631-solved-namespace-prefix-lookup/#findComment-360625 Share on other sites More sharing options...
saipkjai Posted October 3, 2007 Author Share Posted October 3, 2007 hm.. I dont kinda understand what you mean.... let say I have a feed like this <feed xmlns="http://www.w3.org/2005/Atom"> … <content type="xhtml" xmlns:x="http://www.w3.org/1999/xhtml"> <x:div><x:strong>very</x:strong> good</x:div> </content> … </feed> am I suppose to use the lookupprefix('http://www.w3.org/1999/xhtml') to retrieve x within the xmlns:x ? thx Quote Link to comment https://forums.phpfreaks.com/topic/71631-solved-namespace-prefix-lookup/#findComment-360628 Share on other sites More sharing options...
saipkjai Posted October 3, 2007 Author Share Posted October 3, 2007 sorry... I think I meant what you mean and I figure it out. Thx for the help Quote Link to comment https://forums.phpfreaks.com/topic/71631-solved-namespace-prefix-lookup/#findComment-360633 Share on other sites More sharing options...
sKunKbad Posted October 3, 2007 Share Posted October 3, 2007 if you would post your code, it would probably help out other people in the future Quote Link to comment https://forums.phpfreaks.com/topic/71631-solved-namespace-prefix-lookup/#findComment-360835 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.