📜  PHP | XMLReader expand()函数

📅  最后修改于: 2022-05-13 01:56:54.218000             🧑  作者: Mango

PHP | XMLReader expand()函数

XMLReader::expand()函数是PHP中的一个内置函数,用于复制当前节点并返回相应的 DOM 对象。

句法:

DOMNode XMLReader::expand( DOMNode $basenode )

参数:此函数接受单个参数$basenode ,它包含一个 DOMNode,为创建的 DOM 对象定义目标 DOMDocument。

返回值:此函数在成功时返回 DOMNode,在失败时返回 FALSE。

下面的示例说明了PHP中的XMLReader::expand()函数

示例 1:

  • 数据.xml
    
    
        
    This is a div
  • 指数。 PHP
    open('data.xml');
      
    // Move to the first node
    $XMLReader->read();
      
    // Read it as a element
    $element = $XMLReader->expand();
      
    // Print the node value to the browser
    echo $element->nodeValue;
    ?>
    
  • 输出:
    This is a div

示例 2:

  • 数据.xml
    
    
        

            GeeksforGeeks      

  • 指数。 PHP
    open('data.xml');
      
    // Move to the first node
    $XMLReader->read();
      
    // Read it as a element
    $element = $XMLReader->expand();
      
    // Create a new DOMDocument instance
    $DOMDocument = new DOMDocument();
      
    // Append the child to the element
    $DOMDocument->appendChild($element);
      
    // Render the XML in browser
    echo $DOMDocument->saveXML();
    
  • 输出:

参考: https://www. PHP.net/manual/en/xmlreader.expand。 PHP