Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Simple XML GET with php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 134
    Comment on it

    To get the node values from we use xml file with XML Get . The example to get the data from xml.

    Note.xml is xml file, 

    <SUBJECT>
       <COURSE>Android</COURSE>
       <COUNTRY>India</COUNTRY>
       <COMPANY>TutorialsPoint</COMPANY>
       <PRICE>$10</PRICE>
    </SUBJECT>
    

    To get access the xml data by using implexml_load_file().

    <?php
       $xml = simplexml_load_file("note.xml") or die("Error: Object Creation failure");
    ?>
    
    <html>
       <head>
          
          <body>
             
             <?php
                echo $xml->COURSE . "<br>";
                echo $xml->COUNTRY . "<br>";
                echo $xml->COMPANY . "<br>";
                echo $xml->PRICE;
             ?>
             
          </body>
          
       </head>
    </html>

    Having information about how to get node values from xml file :

    <?xml version = "1.0" encoding = "utf-8"?>
    <tutorialspoint>
       
       <course category = "JAVA">
          <title lang = "en">Java</title>
          <tutor>Gopal</tutor>
          <duration></duration>
          <price>$30</price>
       </course>
       
       <course category = "HADOOP">
          <title lang = "en">Hadoop</title>.
          <tutor>Satish</tutor>
          <duration>3>/duration>
          <price>$50</price>
       </course>
       
       <course category = "HTML">
          <title lang = "en">html</title>
          <tutor>raju</tutor>
          <duration>5</duration>
          <price>$50</price>
       </course>
       
       <course category = "WEB">
          <title lang = "en">Web Technologies</title>
          <tutor>Javed</tutor>
          <duration>10</duration>
          <price>$60</price>
       </course>
    
    </tutorialspoint>

    PHP code be as :

    <html>
       <body>
       
          <?php
             $xml = simplexml_load_file("books.xml") or die("Error: Cannot create object");
             
             foreach($xml->children() as $books) { 
                echo $books->title . "<br> "; 
                echo $books->tutor . "<br> "; 
                echo $books->duration . "<br> ";
                echo $books->price . "<hr>"; 
             }
          ?>
          
       </body>
    </html> 

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: