Home Backend Development PHP Tutorial Detailed analysis of PHP5 object simplexml_PHP tutorial

Detailed analysis of PHP5 object simplexml_PHP tutorial

Jul 15, 2016 pm 01:29 PM
file load php5 simplexml str xml analyze object Will of detailed

simplexml_load_file(str file); Load an xml document into a simplexml object. This method returns a handle.

simplexml_load_string(str string); Load an xml document into a simplexml object. Load a simplexml object, 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 a simplexml object element, not a simplexml object handle.

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

$simplexml->asXML() as a string from the SimpleXMLElement object Returns an XML document, which can be used as a saved xml document

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

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

visible, $simplexml->attributes( ) gets all the attributes of an xml element node, but they are included in an [@attributes] array, so you need to get it through $xml = $xml['@attributes']

$simplexml-> ;Children() Returns an array composed of children of simplexml object element node

$simplexml->__construct() Creates a new XML document

$simplexml->getDocNamespaces() This function Returns the namespace defined by the $simplexml object

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

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

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

$simplexml->xpath() Use xpath syntax to Parse a PHP5 object simplexml

Example code 1

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>xml</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>version</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"1.0"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>encoding</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"gbk"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>LeapsoulXML</SPAN><SPAN class=tag>></span></font></strong><span>    </span>
</li>
<li class="alt">
<span>    </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span>    </span>
</li>
<li class="">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span>Leapsoul-PHP网站开发</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span>    </span>
</li>
<li class="alt">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span>http://www.leapsoul.cn</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span>    </span>
</li>
<li class="">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span>分享PHP网站开发与建设的乐趣,教你如何建立网站</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span>David</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span>2009-05-13</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span>QQ:154130270</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span>    </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span>    </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span>    </span>
</li>
<li class="alt">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span>Leapsoul-PHP网站开发</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>name</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span>http://www.leapsoul.cn</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>website</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span>分享PHP网站开发与建设的乐趣,教你如何建立网站</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>description</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span>David</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>bloger</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span>2009-05-13</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>date</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span>        </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span>QQ:154130270</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>qq</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="alt">
<span>    </span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>LeapsoulInfo</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>LeapsoulXML</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
</ol>
Copy after login

We can combine the above PHP5 object simplexml example, plus With your own understanding, you should be able to fully understand this new function.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446334.htmlTechArticlesimplexml_load_file(str file); Load an xml document into a simplexml object. This method returns a handle simplexml_load_string( str string);Load an xml document into a simple...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

How to use PHP functions to process XML data? How to use PHP functions to process XML data? May 05, 2024 am 09:15 AM

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

How do PHP functions return objects? How do PHP functions return objects? Apr 10, 2024 pm 03:18 PM

PHP functions can encapsulate data into a custom structure by returning an object using a return statement followed by an object instance. Syntax: functionget_object():object{}. This allows creating objects with custom properties and methods and processing data in the form of objects.

Analysis of the reasons why the secondary directory of DreamWeaver CMS cannot be opened Analysis of the reasons why the secondary directory of DreamWeaver CMS cannot be opened Mar 13, 2024 pm 06:24 PM

Title: Analysis of the reasons and solutions for why the secondary directory of DreamWeaver CMS cannot be opened. Dreamweaver CMS (DedeCMS) is a powerful open source content management system that is widely used in the construction of various websites. However, sometimes during the process of building a website, you may encounter a situation where the secondary directory cannot be opened, which brings trouble to the normal operation of the website. In this article, we will analyze the possible reasons why the secondary directory cannot be opened and provide specific code examples to solve this problem. 1. Possible cause analysis: Pseudo-static rule configuration problem: during use

What should I pay attention to when a C++ function returns an object? What should I pay attention to when a C++ function returns an object? Apr 19, 2024 pm 12:15 PM

In C++, there are three points to note when a function returns an object: The life cycle of the object is managed by the caller to prevent memory leaks. Avoid dangling pointers and ensure the object remains valid after the function returns by dynamically allocating memory or returning the object itself. The compiler may optimize copy generation of the returned object to improve performance, but if the object is passed by value semantics, no copy generation is required.

Analyze whether Tencent's main programming language is Go Analyze whether Tencent's main programming language is Go Mar 27, 2024 pm 04:21 PM

Title: Is Tencent’s main programming language Go: An in-depth analysis. As China’s leading technology company, Tencent has always attracted much attention in its choice of programming languages. In recent years, some people believe that Tencent mainly adopts Go as its main programming language. This article will conduct an in-depth analysis of whether Tencent's main programming language is Go, and give specific code examples to support this view. 1. Application of Go language in Tencent Go is an open source programming language developed by Google. Its efficiency, concurrency and simplicity are loved by many developers.

What is the difference between arrays and objects in PHP? What is the difference between arrays and objects in PHP? Apr 29, 2024 pm 02:39 PM

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values ​​are passed and object references are passed.

See all articles