Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/71631-solved-namespace-prefix-lookup/
Share on other sites

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>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.