Home  >  Article  >  Backend Development  >  Detailed explanation of php SimpleXML() function usage

Detailed explanation of php SimpleXML() function usage

怪我咯
怪我咯Original
2017-07-14 14:12:571397browse

SimpleXML The function allows you to convert XML to an object, which can be processed through ordinary property selectorsor array iterators, Just like any other object. Some of these functions require the latest PHP version.

INSTALLATION: The SimpleXML functions are part of the PHP core, no installation is required to use these Function

Related functions are introduced as follows:

##addAttribute()Add an attribute to the SimpleXML element5addChild()Add a child element to the SimpleXML element5##asXML()Stringattributes()children()getDocNamespaces() namespace of the XML documentgetName()##getNamespaces()Get the namespace from XML data5registerXPathNamespace()Create for the next XPath Namespace contextsimplexml_import_dom()Get the SimpleXMLElement object from the DOM node5simplexml_load_file()Get the SimpleXMLElement object from the XML document5simplexml_load_string() Get a SimpleXMLElement object from an XML string5xpath()Run an XPath query on XML data5Example
Function Description PHP Version
construct() Create a new SimpleXMLElement object 5
Get XML from SimpleXML element 5
Get the attributes of the SimpleXML element 5
Get the specified node The child node 5
Get the 5
Get the name of the SimpleXML element 5
query5

item; 
        $wordsLength = sqlserver/42852.htm target=_blank >count($items); 
        //获取所有节点的下的节点值 
 for($i=0;$i<$wordsLength;$i++){ 
  $word=$items[$i]; 
  echo $word->word.'-----'.$word->trans.'-----'.$word->phonetic.'
'; } //simplexml结合xpath无所不能 $words = $lib->xpath("//word"); //获取属性的方法 echo $words[0]['add'].'
'; echo $items[0]['pp']; ?>

The above is the detailed content of Detailed explanation of php SimpleXML() function usage. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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