PHP Reads XML values

Source: Internet
Author: User
PHP reads XML in the third case: the XML file (Cy.xml) is as follows:
 
 
   
    
    
     1
     
    
     2
     
    
     3
     
  
  
  
 
    
    
    
     4
     
    
     5
     
    
     6 
    
  
  
  
 
   
 
 

  
 The php file (cy.php) is as follows (and the first time remains unchanged):
 Load (' Cy.xml '); foreach ($xml->getelementsbytagname_r (' list ') as $list) {$value = $list->firstchild-> Nodevalue;echo $value. "
";}? >cy.php output: 123456===========php read XML fourth case, keep cy.xml unchanged, change Cy.php:XML file (Cy.xml) as follows: 1 2 3 ) 4 5 6 The php file (cy.php) is as follows: Load (' Cy.xml '), $main = $xml->getelementsbytagname_r (' main '), foreach ($main as $main) {$list = $main Getelementsbytagname_r ("list"), foreach ($list as $list) {$value = $list->firstchild->nodevalue; PHP reads XML in the third case: the XML file (Cy.xml) is as follows: 1 2 3 4 5 6 /c7> The php file (cy.php) is as follows (and the first time remains unchanged): Load (' Cy.xml '); foreach ($xml->getelementsbytagname_r (' list ') as $list) {$value = $list->firstchild-> Nodevalue;echo $value. "
";}? >cy.php output: 123456===========php read XML fourth case, keep cy.xml unchanged, change Cy.php:XML file (Cy.xml) as follows: 1 2 3 4 5 6 The php file (cy.php) is as follows: Load (' Cy.xml '), $main = $xml->getelementsbytagname_r (' main '), foreach ($main as $main) {$list = $main Getelementsbytagname_r ("list"), foreach ($list as $list) {$value = $list->firstchild->nodevalue; echo $value. "
";}}? >cy.php output: 123456 Why two times cy.php is different, but the output is the same? Let's take a look at the next example ==============php read the fifth case of XML, change the Cy.xml, and keep cy.php in the fourth case: The XML file (Cy.xml) is as follows: 1 2 3 4 5 6 7 8 9 PHP files (cy.php) are the same as in the fourth case: Load (' Cy.xml '), $main = $xml->getelementsbytagname_r (' main '), foreach ($main as $main) {$list = $main Getelementsbytagname_r ("list"), foreach ($list as $list) {$value = $list->firstchild->nodevalue;echo $value. "
";}}? >cy.php output is: 123456 why 7 8 9 7,8,9 is not read? Because our cy.php only read The contents of the tag. The content in the tag is not read. The "tag" we refer to here is called "node" in XML; Note: $xml->load (' cy.xml '); load XML file $xml->loadxml (' Cy.xml '); Load a string in XML format
  • 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.