This post was last edited by Huenke on 2013-10-25 15:58:22
Xml
Structure for nodes under node and node below.
I want to do a triple loop.
foreach ()
{
Deposit Company Name
foreach ()
{
Name of the Depositary Department
foreach ()
{Save Leaf name}
}
}
How can I parse it, please?
Reply to discussion (solution)
Did SimpleXML use it?
SimpleXML didn't resolve it.
Can you give me a little bit of debugging?
What kind of data format do you want? , organize your data structure below.
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 parent_id: ', $node, ' \ n ';} $result = $xml->xpath ('//node[@type =2]/. /@id '), while (list (, $node) = each ($result)) {echo ' @ leaf parent_id: ', $node, ' \ n ';}? >
$s =<<< XML
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"; foreach ($node->node as $node) {foreach ($node->attributes () as $k + $v) echo "$k = = $v \ n"; } }}
id = c5569e2c-0f4a-4ec2-86ba-736b79eca18c
Name = a company
Type = 0
id = 4f2b55e9-e10a-496b-8bca-60e6f26daee5
Name = Department 1
Type = 1
id = 363
name = Leaf 1
Type = 2
Playurl = http://XXXXXXX363
id = 0c5ce42f-ba31-4b7a-8173-79ecae4a73ca
Name = Department 2
Type = 1
id = 241
name = Leaf 1
Type = 2
Playurl = http://xxxxx=241
id = 356
name = Leaf 1
Type = 2
Playurl = xxxxxxxxx=356
It's a tree-like structure.
Such as
Company A
Department 1
Leaf 1
Department 2
。。。。
I'll give you one more, it's a tree-like change.
!--? php$string = <<
XML; $xml = new SimpleXMLElement ($string);//Var_export ($xml); $xmlIterator = new Recursi Veiteratoriterator (New Simplexmliterator ($string), Recursiveiteratoriterator::self_first); foreach ($xmlIterator as $nodeName = = $node) {echo str_repeat ('-', (int) $node [' type ']); echo $node [' id '], ', ', $node [' name '], Php_eol;}?
Top
$xml = new SimpleXMLElement ($string);
This sentence can be deleted, before the commissioning of the time left