SimpleXMLElement无法查找节点属性

时间:2015-08-13 19:39:00

标签: php simplexml

Feed的一个条目: -

<entry>
    <id>tag:blogger.com,1999:blog-8729980629780635785.post-7267854162055446813</id>
    <published>2015-08-12T10:51:00.000-04:00</published>
    <updated>2015-08-12T10:51:07.914-04:00</updated>
    <category scheme="http://www.blogger.com/atom/ns#" term="Cancer Prevention" />
    <category scheme="http://www.blogger.com/atom/ns#" term="Cervical Cancer" />
    <category scheme="http://www.blogger.com/atom/ns#" term="curcumin" />
    <category scheme="http://www.blogger.com/atom/ns#" term="HPV" />
    <category scheme="http://www.blogger.com/atom/ns#" term="Mouth Cancer" />
    <category scheme="http://www.blogger.com/atom/ns#" term="STD" />
    <category scheme="http://www.blogger.com/atom/ns#" term="Throat Cancer" />
    <category scheme="http://www.blogger.com/atom/ns#" term="Tonsil Cancer" />
    <category scheme="http://www.blogger.com/atom/ns#" term="turmeric" />
    <title type="text">Curcumin May Prevent HPV-Related Cancers</title>
    <content type="html">&lt;h2&gt;Maylin Rodriguez-Paez RN&lt;/h2&gt;&lt;a href="http://3.bp.blogspot.com/-dPF4cftq7l8/VctX0J56YyI/AAAAAAAAEXo/yHPgb0E_Ha8/s1600/trun.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="167" src="http://3.bp.blogspot.com/-dPF4cftq7l8/VctX0J56YyI/AAAAAAAAEXo/yHPgb0E_Ha8/s1600/trun.jpg" width="320" /&gt;&lt;/a&gt;HPV is the most common sexually transmitted disease in the United States. It infects at least fourteen million annually and most are unware of their infection status.&lt;sup&gt;1&lt;/sup&gt;&lt;br /&gt;&lt;br /&gt;For the most part, HPV does not cause any harm to the infected individual. However, in a minority of cases, HPV can lead to the development of mouth, throat, tonsil, and &lt;a href="http://blog.lifeextension.com/2014/04/mushroom-extract-treat-cervical-cancer.html" target="_blank"&gt;cervical cancers&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Interestingly, a new study shows curcumin may offer help in combating the HPV virus and preventing HPV-induced cancers. The results were published in the online journal, &lt;i&gt;Ecancermedicalscience&lt;/i&gt;.   &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Curcumin Silences Cancer-Causing Genes &lt;/h3&gt;Previous studies show curcumin combats multiple types of &lt;a href="http://www.lifeextension.com//Magazine/2011/3/How-Curcumin-Protects-Against-Cancer/Page-01" target="_blank"&gt;cancers&lt;/a&gt;. Benefits have been seen for cancers of the breast, prostate, pancreas, and colon.&lt;br /&gt;&lt;br /&gt;For the current study, oral cancer cells infected with the HPV virus were cultivated along with curcumin extract.   According to the results of the study, curcumin suppressed the activity of transcription factors (proteins that control the activity of genes) needed for the cancer cells to develop.&lt;sup&gt;2&lt;/sup&gt;&lt;br /&gt;&lt;br /&gt;One transcription factor in particular, NF-kB, is known for being involved in cancer development.   Curcumin was also shown to silence cancer-promoting genes (oncogenes) and caused HPV infected cells to undergo apoptosis (cell- suicide).&lt;sup&gt;2&lt;/sup&gt;&lt;br /&gt;&lt;br /&gt;HPV-related cancers (especially those developing in the throat and mouth) are growing within the United States. Prior research shows curcumin helps to clear the HPV virus from cervical tissue.&lt;sup&gt;3&lt;/sup&gt;&lt;br /&gt;&lt;br /&gt;Despite the results of this current study, more research is needed to confirm curcumin’s benefits against HPV-related cancers.   &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;How to Get More Curcumin in Your System&lt;/h3&gt;Curcumin is an antioxidant found in the herb turmeric. It gives turmeric its characteristic yellow color.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;While adding turmeric to food is an excellent idea, it’s actually not the best way to obtain curcumin in your diet. Unfortunately, curcumin is poorly absorbed into the bloodstream.&lt;br /&gt;&lt;br /&gt;Fortunately, supplementing with a curcumin extract offers a way to increase curcumin levels in the blood. Look for preparations that contain &lt;a href="http://www.lifeextension.com//Magazine/2014/2/Bio-Enhanced-TURMERIC-Compounds-Block-Multiple-Inflammatory-Pathways/Page-01" target="_blank"&gt;phospholipids &lt;/a&gt;for optimal absorption.   &lt;br /&gt;&lt;br /&gt;&lt;h2&gt;References:&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;Available at: &lt;a href="http://www.cdc.gov/std/hpv/stdfact-hpv.htm"&gt;http://www.cdc.gov/std/hpv/stdfact-hpv.htm&lt;/a&gt;. Accessed May 4&lt;sup&gt;th&lt;/sup&gt;, 2015.&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Ecancermedicalscience&lt;/i&gt;. 2015 Apr 23;9:525.&amp;nbsp;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Asian Pac J Cancer Prev&lt;/i&gt;. 2013;14(10):5753-9.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/LifeExtensionBlog/~4/BhZ_UDkx0gc" height="1" width="1" alt=""/&gt;</content>
    <link rel="replies" type="application/atom+xml" href="http://blog.lifeextension.com/feeds/7267854162055446813/comments/default" title="Post Comments" />
    <link rel="replies" type="text/html" href="http://blog.lifeextension.com/2015/08/curcumin-may-prevent-hpv-related-cancers.html#comment-form" title="0 Comments" />
    <link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8729980629780635785/posts/default/7267854162055446813" />
    <link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8729980629780635785/posts/default/7267854162055446813" />
    <link rel="alternate" type="text/html" href="http://blog.lifeextension.com/2015/08/curcumin-may-prevent-hpv-related-cancers.html" title="Curcumin May Prevent HPV-Related Cancers" />
    <author>
        <name>LifeExtension</name>
        <uri>http://www.blogger.com/profile/00252359139805937161</uri>
        <email>noreply@blogger.com</email>
        <gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" />
    </author>
    <media:thumbnail
        xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-dPF4cftq7l8/VctX0J56YyI/AAAAAAAAEXo/yHPgb0E_Ha8/s72-c/trun.jpg" height="72" width="72" />
        <thr:total>0</thr:total>
</entry>

代码: -

<?php

$url = 'http://feeds.feedburner.com/LifeExtensionBlog';

$XmlObject = new SimpleXmlElement( file_get_contents($url) );

foreach($XmlObject->entry as $entry) {

    $content = (string) $entry->content[0];

    $post_title = (string) $entry->title[0];

    $tmp = $entry->xpath('media:thumbnail/@url');

    var_dump($tmp);

    $image_url = (string) $tmp;

    echo 'THE IMAGE:' . $image_url . "<br><hr><br>";
    echo $post_title . "<br>";
    echo $content . "<br>";     

}

输出: -

Warning: SimpleXMLElement::xpath(): Undefined namespace prefix in C:\wamp\www\test-4.php on line 20

标题和内容打印正常。

0 个答案:

没有答案