Get the App
SLTechnology News&Howtos  ›  Development  › 

Instance usage of PHP5 object simplexml

Shulou Source: shulou.com Published: 2022-06-03 19:03:37 11月12日 Update

This article mainly explains "the example usage of PHP5 object simplexml". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the example usage of PHP5 object simplexml".

The PHP5 object simplexml is a new object for XML. In this article, we will introduce the properties and methods of the PHP5 object simplexml in detail. I hope you can have a deep understanding of this new object through this article.

Simplexml_load_file (str file); loads an xml document into a simplexml object, and this method returns a handle

Simplexml_load_string (str string); loads a xml document into a simplexml object, and this method returns a handle

Simplexml_import_dom (data) this function converts a dom node into a simplexml object, where data is a practical DOM node

$simplexml- > addAttribute (name,value) adds an attribute to the simplexml object element. Note that it is the simplexml object element, not the simplexml object handle.

$simplexml- > addChlid (name,value) adds a child node to the specified XML node

$simplexml- > asXML () returns the XML document as a string from the SimpleXMLElement object, which can be used to save the xml document

$simplexml- > attributes () returns an array of attributes of the simplexml element node of the PHP5 object

Running the above code will print out an array of Array ([@ attributes] = > Array ([name] = > cx,html [tt] = > ddd))

As you can see, $simplexml- > attributes () gets all the attributes of a xml element node, but is contained in a [@ attributes] array, so get it through $xml = $xml ['@ attributes']

$simplexml- > Children () returns an array of children of simplexml object element nodes

$simplexml- > _ _ construct () create a new XML document

$simplexml- > getDocNamespaces () this function returns the namespace defined by the $simplexml object

$simplexml- > getName () returns the name of the $simplexml object element, that is, the signature

$simplexml- > getNamespaces () returns the namespace used by the $simplexml object

$simplexml- > registerXpathNamespace () this function creates a namespace context for the next XPATH query

$simplexml- > xpath () uses the syntax of xpath to parse a PHP5 object simplexml

Example code 1

Leapsoul-PHP website development http://www.leapsoul.cn share the fun of PHP website development and construction, teach you how to build a website David 2009-05-13 QQ:154130270 Leapsoul-PHP website development http://www.leapsoul.cn share the fun of PHP website development and construction Teach you how to build a website David 2009-05-13 QQ:154130270 Thank you for your reading The above is the content of "instance usage of PHP5 object simplexml". After the study of this article, I believe you have a deeper understanding of the instance usage of PHP5 object simplexml, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Object node element website instance document attribute website development development function handle array space learning fun code content this method article construction Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Technology Linux vpn NVidia