/*One-dimensional array to XMLIdeas:Loop an array of each cell and add it to the XML document node*//*$arr = Array (' Name ' and ' Ding Three ',' Age ' =>29);function Arr2xml ($arr) {$simxml = new SimpleXMLElement (' ");How do simplexmlelement
To get an XML-type object:
Copy Code code as follows:
$resp = $this->c->execute ($req, $sessionKey);//Get XML Object
$items = $resp->items;
Then read the value of the object, use $items->item, or $items->item->price, so it is
I shared the code for the first time. Today I used simplexml to parse xml files and searched for a lot of methods to directly convert object array objects into arrays. I found that many codes are not useful and many use recursion, share my code
SimpleXML provides a simple and fast method of XML operation, which greatly improves the efficiency of XML operation.But sometimes careless can bring a little trouble, look at the following code:$xml =simplexml_load_string (' $title = $xml->title;
Get an XML-type object:
Copy CodeThe code is as follows:
$resp = $this->c->execute ($req, $sessionKey);//Get an XML object
$items = $resp->items;
Then read the value of the object, with $items->item, or $items->item->price, so the operation is
Get an XML-type object:
Copy CodeThe code is as follows:
$resp = $this->c->execute ($req, $sessionKey);//Get an XML object
$items = $resp->items;
Then read the value of the object, with $items->item, or $items->item->price, so the operation is
Xml dom (11) and xmldom in php
7.Create a node
In dom operations, you must find the parent node for addition, deletion, and modification operations.
1. DOMElement DOMDocument: createElement (string $ name [, string $ value])
Create a node. A Node
ArticleDirectory
Syntax
Return Value
Definition and usage
The _ construct () function creates a new simplexmlelement object.
If yes, the function returns an object. If it fails, false is returned. Syntax
_ Construct (data,
1. Use DOM to generate and read XML files
Instance 1:
Copy codeThe Code is as follows: // Creates XML string and XML document using the DOM
$ Dom = new DomDocument ('1. 0 ');
// Add root-
$ Books = $ dom-> appendChild ($ dom-> createElement_x_x
Php parses xml in four ways. XML processing is often encountered during the development process. PHP also has rich support for it. This article only briefly describes some of the parsing technologies, including Xml parser, SimpleXML, XMLReader, and
Third, PHP simplexml implementation of XML additions and deletions 1, load XML file into memory, and form SimpleXML objectSimpleXMLElement simplexml_load_file (String $filename): Load XML file into memory and generate SimpleXML
7. Create a Node
In DOM operations, adding and deleting operations must find the parent node
1, DomElement domdocument::createelement (String $name [, String $value])
Creates a node and returns a Node object
String $name: Name of the node (element
The following small series will introduce four simple methods (with examples) for parsing xml in php ). I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the XML processing that we often
Definition and usage
The __construct () function creates a new SimpleXMLElement object.
If successful, the function returns an object. If it fails, it returns false.
Grammar
__construct (Data,options,is_url,ns,is_prefix)
Parameters
: This article mainly introduces XMLDOM (11) in php. if you are interested in the PHP Tutorial, refer to it. 7. create a node
In dom operations, you must find the parent node for addition, deletion, and modification operations.
1. DOMElement
PHP Simple XML handles the most common XML tasks, while the rest of the tasks are handled by other extensions, which are described in more detail in this article.
What is PHP SimpleXML?
SimpleXML is a new feature in PHP 5.
The SimpleXML extension
DomElement
DomElement domdocument::createelement (String $name [, String $value])
Creating a Node Element
String $name: node name
String $value: The value of the node
8. Adding nodes
domnode domnode::appendchild (Domnode $newnode)
Add child
I. Using the DOM to generate and read XML files
Example one:
Copy Code code as follows:
Creates XML string and XML document using the DOM
$dom = new DOMDocument (' 1.0 ');
Add Root-
$books = $dom->appendchild
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.