【问题标题】:xpath simplexml tags query and how to get node valuesxpath simplexml标签查询以及如何获取节点值
【发布时间】:2013-05-02 06:21:47
【问题描述】:

我使用 simpleXML 进行 xpath 查询,我想用它来获取标签标题、描述和链接的节点值。但我不知道如何输出它们,例如只输出标题内容。

<item>
   <title>Cell Phone Plans That Make You Go Hmmm</title> 
   <link>http://www.articlegeek.com/computers/telecommunication_articles/10574-    cellphoneplanst.htm</link> 
   <description>Cell phone plans across the globe vary a great deal. Some say that cell phone plans in the US are more costly. However, there are some advantages to the cell phone plans in the US which may balance the difference.</description> 
</item> 

function xmlXpath()
{
    $xml = xmlParse();

    $userIN = "cell";
    $nodesT = $xml->xpath("
       //*
       [
           text()
           [
               contains(
                   translate(.,'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 
                               'abcdefghjiklmnopqrstuvwxyz'),
                   '".$userIN."'
               )
           ]
       ]
    ");
    return $nodesT;
}

【问题讨论】:

  • 请在您的问题中发布您的 XML 代码,而不是链接。

标签: php simplexml


【解决方案1】:

编辑:考虑到您的 xpath,请执行以下操作:

foreach ($nodesT as $nodeT) echo "$nodeT <br />";

看到它的工作:http://codepad.viper-7.com/WKDfvJ

【讨论】:

  • 抱歉,我不知道如何显示 xml,所以我将网站链接到它所在的位置。
  • @DOWmad:简单地将其复制到您的问题中并像代码一样缩进。
猜你喜欢
  • 2023-03-13
  • 1970-01-01
  • 2011-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多