How to parse nested xml into php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • semanticnotion
    New Member
    • Sep 2010
    • 66

    How to parse nested xml into php?

    Hi all i have an xml file e.g
    Code:
    <recipe>
    <id>abc</id>
    <name>abc</name>
    <instructions>
    <instruction>
    <id>abc</id>
    <text>abc</text>
    </instruction>
    <instruction>
    <id>abc2</id>
    <text>abc2<text>
    <instruction>
    <instructions>
    <recipe>
    on my php file i use

    Code:
    $url = "cafe.xml";
    // get xml file contents
    $xml = simplexml_load_file($url);
    
    // loop begins
    foreach($xml->recipe as $recipe)
    {
    code;
    }
    but it only retrieve the recipe id and name so how can i retrieve the instructions.
  • Claire Julia
    New Member
    • Nov 2010
    • 1

    #2
    you need to use Xpath.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      but it only retrieve the recipe id and name so how can i retrieve the instructions.
      I doubt that statement.

      unless you have the same XML errors in your original code, all is retrieved properly. you would be able to get the <instructions > element. depending on what you want exactly, an XPath expression might be faster.

      Comment

      • semanticnotion
        New Member
        • Sep 2010
        • 66

        #4
        Thanks Dormilich for your reply now i solved the thread read the .xml successfully in php file but now my question is how can i read the client request(web service request) and update the data accordingly in php file.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          how you read the client request depends on its nature (SOAP, XML-RPC, etc.)

          Comment

          • semanticnotion
            New Member
            • Sep 2010
            • 66

            #6
            which one is best SOAP or XML-RPC
            and would you like to share some useful tutorial about the best one cause i have no idea.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              I have no idea what is best.

              Comment

              Working...