<bdo id='LtRYI'></bdo><ul id='LtRYI'></ul>

<small id='LtRYI'></small><noframes id='LtRYI'>

    <legend id='LtRYI'><style id='LtRYI'><dir id='LtRYI'><q id='LtRYI'></q></dir></style></legend>
    1. <i id='LtRYI'><tr id='LtRYI'><dt id='LtRYI'><q id='LtRYI'><span id='LtRYI'><b id='LtRYI'><form id='LtRYI'><ins id='LtRYI'></ins><ul id='LtRYI'></ul><sub id='LtRYI'></sub></form><legend id='LtRYI'></legend><bdo id='LtRYI'><pre id='LtRYI'><center id='LtRYI'></center></pre></bdo></b><th id='LtRYI'></th></span></q></dt></tr></i><div id='LtRYI'><tfoot id='LtRYI'></tfoot><dl id='LtRYI'><fieldset id='LtRYI'></fieldset></dl></div>

      1. <tfoot id='LtRYI'></tfoot>

        php domdocument获取属性值所在的节点值

        时间:2024-04-13
        1. <legend id='zLXcS'><style id='zLXcS'><dir id='zLXcS'><q id='zLXcS'></q></dir></style></legend>
          • <bdo id='zLXcS'></bdo><ul id='zLXcS'></ul>
            <i id='zLXcS'><tr id='zLXcS'><dt id='zLXcS'><q id='zLXcS'><span id='zLXcS'><b id='zLXcS'><form id='zLXcS'><ins id='zLXcS'></ins><ul id='zLXcS'></ul><sub id='zLXcS'></sub></form><legend id='zLXcS'></legend><bdo id='zLXcS'><pre id='zLXcS'><center id='zLXcS'></center></pre></bdo></b><th id='zLXcS'></th></span></q></dt></tr></i><div id='zLXcS'><tfoot id='zLXcS'></tfoot><dl id='zLXcS'><fieldset id='zLXcS'></fieldset></dl></div>
                <tbody id='zLXcS'></tbody>

                <small id='zLXcS'></small><noframes id='zLXcS'>

              • <tfoot id='zLXcS'></tfoot>

                  本文介绍了php domdocument获取属性值所在的节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我的 XML 如下所示:

                  Say my XML looks like this:

                  <record>
                    <row name="title">this item</row>
                    <row name="url">this url</row>
                  </record>
                  

                  现在我正在做这样的事情:

                  Now I'm doing something like this:

                  $xml = new DOMDocument();
                  $xml->load('xmlfile.xml');
                  
                  echo $xml->getElementByTagName('row')->item(0)->attributes->getNamedItem('title')->nodeValue;
                  

                  但这只是给了我:

                  注意:试图获取非对象 id 的属性

                  NOTICE: Trying to get property of non-object id

                  有人知道如何获取name"属性值为title"的节点值吗?

                  Does anybody know how to get the node value where the "name" attribute has value "title"?

                  推荐答案

                  试试:

                  $xml = new DOMDocument();
                  $xml->loadXml('
                  <record>
                    <row name="title">this item</row>
                    <row name="url">this url</row>
                  </record>
                  ');
                  
                  $xpath = new DomXpath($xml);
                  
                  // traverse all results
                  foreach ($xpath->query('//row[@name="title"]') as $rowNode) {
                      echo $rowNode->nodeValue; // will be 'this item'
                  }
                  
                  // Or access the first result directly
                  $rowNode = $xpath->query('//row[@name="title"][1]')->item(0);
                  if ($rowNode instanceof DomElement) {
                      echo $rowNode->nodeValue;
                  }
                  

                  这篇关于php domdocument获取属性值所在的节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP DOMDocument 更改标签属性值 下一篇:使用 SimpleXML 获取属性和值

                  相关文章

                  <small id='32xpF'></small><noframes id='32xpF'>

                • <tfoot id='32xpF'></tfoot>

                  1. <i id='32xpF'><tr id='32xpF'><dt id='32xpF'><q id='32xpF'><span id='32xpF'><b id='32xpF'><form id='32xpF'><ins id='32xpF'></ins><ul id='32xpF'></ul><sub id='32xpF'></sub></form><legend id='32xpF'></legend><bdo id='32xpF'><pre id='32xpF'><center id='32xpF'></center></pre></bdo></b><th id='32xpF'></th></span></q></dt></tr></i><div id='32xpF'><tfoot id='32xpF'></tfoot><dl id='32xpF'><fieldset id='32xpF'></fieldset></dl></div>
                    <legend id='32xpF'><style id='32xpF'><dir id='32xpF'><q id='32xpF'></q></dir></style></legend>
                    • <bdo id='32xpF'></bdo><ul id='32xpF'></ul>