1

i don't know why am I not getting all results what i want from the xml file.

Here's my code:

<?php
$xml=simplexml_load_file("http://2strok.com/gen/maler.xml") or 
     die("Error: Cannot create object");
    foreach($xml->children() as $books) { 
    echo $books->XResult->Contacts->XContact->Name . "<br>";
    echo $books->XResult->Contacts->XContact->Value . "<br>"; 
    echo $books->XResult->Contacts->XContact->VisitationAddress . "
    <br>"; 
            } 
?> 

I'm using php foreach but i'm getting only the first line :(

1 Answer 1

2

You could try something like this :

$xml=simplexml_load_file("http://2strok.com/gen/maler.xml") or
     die("Error: Cannot create object");
foreach($xml->ResultList->XResult as $res) {
    if ($res->Contacts->XContact) {
        echo $res->Contacts->XContact->Name . "<br>";
        echo $res->Contacts->XContact->Value . "<br>";
        echo $res->Contacts->XContact->VisitationAddress . "<br>";
    }
}

Or this, if you want all contacts :

$xml=simplexml_load_file("http://2strok.com/gen/maler.xml") or
     die("Error: Cannot create object");
foreach($xml->ResultList->XResult as $res) {
    foreach ($res->Contacts->XContact as $elm) {
        echo $elm->Name . "<br>";
        echo $elm->Value . "<br>";
        echo $elm->VisitationAddress . "<br>";
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you so much... the the second one was perfect ;) LOVE YA
@Zabi You're welcome. Please, you could close your question is it helps. meta.stackexchange.com/questions/5234/… Thanks :)
I need to wait a little bit, cuz i can't vote it that fast :D
I was actually talking about that one too :P
I do have one more question from you Mr @Syscall.. how can i get the Coordinate->lat and lot ? i tried all ways but not any sucsess :S
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.