High score online Help XML parsing

Source: Internet
Author: User
Tags xpath
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

  • Related Article

    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.