High-score online XML parsing

Source: Internet
Author: User
High score online help XML parsing this post was last edited by HUENKE from 2013-10-2515: 58: 22 & lt ;? Xml & nbsp; version1.0 & nbsp; encodingutf-8? & Gt; & lt; nodes & gt; & lt; node & nbsp; idc5569e2c-0f4a-4ec2-86ba-736b79ec high score online help XML parsing

This post was last edited by HUENKE at 15:58:22




Type = "0">











The structure is nodes. There are nodes under the node.
I want to create a triple loop
Foreach ()
{
Company name
Foreach ()
{
Save department name
Foreach ()
{Store leaf name}
}
}

How can I resolve it,

Xml

Share:


------ Solution --------------------
What data format do you want ?, Organize the data structure by yourself.

$ String = <

Type = "0">









XML;

$ Xml = new SimpleXMLElement ($ string );

$ Result = $ xml-> xpath ([email protected] ');
While (list (, $ node) = each ($ result )){
Echo [email protected]: ', $ node, "\ n ";
}
$ Result = $ xml-> xpath ([email protected] ');
While (list (, $ node) = each ($ result )){
Echo [email protected]: ', $ node, "\ n ";
}
$ Result = $ xml-> xpath ('// node [@ type = 1]/.. [email protected]');
While (list (, $ node) = each ($ result )){
Echo [email protected] _ id: ', $ node, "\ n ";
}
$ Result = $ xml-> xpath ('// node [@ type = 2]/.. [email protected]');
While (list (, $ node) = each ($ result )){
Echo [email protected] _ id: ', $ node, "\ n ";
}

?>

------ Solution --------------------
$ S = <XML


Type = "0">









XML;
$ Xml = simplexml_load_string ($ s );

Foreach ($ xml-> node as $ node ){
Foreach ($ node-> attributes () as $ k => $ v) echo "$ k => $ v \ n ";
Foreach ($ node-> node as $ node ){
Foreach ($ node-> attributes () as $ k => $ v) echo "$ k => $ v \ n ";

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.