Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • simple XML with PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 121
    Comment on it

    The simple XML parser

    It is used to parse Name, attributes and textual content.

    simplexml_load_file()

    This function is the one which always requires a file path as mandatory parameter.

    simplexml_load_file(($fileName,$class,$options,$ns,$is_prefix)

    simplexml_load_string()

    This function always required the string.

    simplexml_load_string($XMLData,$class,$options,$ns,$is_prefix)

    simplexml_import_dom()

    This function accepts DOM formatted XML content and it converts into simple XML.

    simplexml_load_string($DOMNode,$class)
    

    The following example to parse a xml data file.

    <?php
       $data = "<?xml version = '1.0' encoding = 'UTF-8'?>
       
       <note>
          <Course>Android</Course>
          <Subject>Android</Subject>
          <Company>TutorialsPoint</Company>
          <Price>$10</Price>
       </note>";
       
       $xml = simplexml_load_string($data) or die("Error: Cannot create object");
    ?>
    <html>
    
       <head>
          <body>
             
             <?php
                print_r($xml);
             ?>
          
          </body>
       </head>
       
    </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: