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-736b 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 ('// node/@ name ');
While (list (, $ node) = each ($ result )){
Echo '@ name:', $ node, "\ n ";
}
$ Result = $ xml-> xpath ('// node/@ ID ');
While (list (, $ node) = each ($ result )){
Echo '@ id:', $ node, "\ n ";
}
$ Result = $ xml-> xpath ('// node [@ type = 1]/../@ ID ');
While (list (, $ node) = each ($ result )){
Echo '@ department's parent_id:', $ node, "\ n ";
}
$ Result = $ xml-> xpath ('// node [@ type = 2]/../@ ID ');
While (list (, $ node) = each ($ result )){
Echo '@ Leaf's parent_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 ";