Home > Backend Development > PHP Tutorial > Analysis of SimpleXML function usage in PHP, phpsimplexml_PHP tutorial

Analysis of SimpleXML function usage in PHP, phpsimplexml_PHP tutorial

WBOY
Release: 2016-07-13 10:13:00
Original
933 people have browsed it

Analysis of SimpleXML function usage in PHP, phpsimplexml

The example in this article describes the usage of the SimpleXML function in php. This function allows you to convert XML into objects and is shared with everyone for your reference. The specific analysis is as follows:

SimpleXML functions allow you to convert XML to an object, which can be processed just like any other object via ordinary attribute selectors or array iterators. Some of these functions require the latest PHP version.

Installation: SimpleXML functions are part of the core of PHP. You can use these functions without installation. The code is as follows:

Copy code The code is as follows:
//Return all content as object
$lib = simplexml_load_file("cet4.xml");
//Return the obtained item node in the form of an array
$items=$lib->item;
           $wordsLength = sqlserver/42852.htm target=_blank >count($items);
//Get the node values ​​under all nodes
for($i=0;$i<$wordsLength;$i++){
$word=$items[$i];
echo $word->word.'-----'.$word->trans.'-----'.$word->phonetic.'
';
}
//simplexml combined with xpath is omnipotent
$words = $lib->xpath("//word");
//Method to get attributes
echo $words[0]['add'].'
';
echo $items[0]['pp'];
?>

The relevant functions are introduced as follows:
函数 描述 PHP版本
__construct() 创建一个新的 SimpleXMLElement 对象 5
addAttribute() 给 SimpleXML 元素添加一个属性 5
addChild() 给 SimpleXML 元素添加一个子元素 5
asXML() 从 SimpleXML 元素获取 XML 字符串 5
attributes() 获取 SimpleXML 元素的属性 5
children() 获取指定节点的子节点 5
getDocNamespaces() 获取 XML 文档的命名空间 5
getName() 获取 SimpleXML 元素的名称 5
getNamespaces() 从 XML 数据获取命名空间 5
registerXPathNamespace() 为下一次 XPath 查询创建命名空间语境 5
simplexml_import_dom() 从 DOM 节点获取 SimpleXMLElement 对象 5
simplexml_load_file() 从 XML 文档获取 SimpleXMLElement 对象 5
simplexml_load_string() 从 XML 字符串获取 SimpleXMLElement 对象 5
xpath() 对 XML 数据运行 XPath 查询 5

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917682.htmlTechArticleAnalysis of usage of SimpleXML function in PHP, phpsiimplexml This article describes the usage of SimpleXML function in php. This function is allowed You convert XML into objects and share them with everyone for your reference...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template