0

I'm generating XML data within a PHP file:-

    private static function getAddressesAsXML($addressArr) {

    $addressXML = new SimpleXMLElement("<addresslist></addresslist>");
    $addressXML->addAttribute("resultcount",(int)self::get_resultcount());

    $addressIndex = 0;

    foreach ($addressArr as $addressObject) {

        $addressNode = $addressXML->addChild("address");
        $addressNode->addAttribute("id",(int)$addressIndex);

        $addressNode->addChild("pickup",htmlspecialchars($addressObject->get_pickup()));
        $addressNode->addChild("dropoff",htmlspecialchars($addressObject->get_dropoff()));
        $addressNode->addChild("BookingDateTime",$addressObject->get_bookingtime());
        $addressNode->addChild("Car",$addressObject->get_car());
        $addressNode->addChild("JbMessage",$addressObject->get_status());
        $addressNode->addChild("Zone",$addressObject->get_zone());
        $addressNode->addChild("CustomerFare",$addressObject->get_fare());
        $addressNode->addChild("PassName",$addressObject->get_passenger());
        $addressNode->addChild("CarType",$addressObject->get_cartype());
        $addressNode->addChild("Tel",$addressObject->get_tel());
        $addressNode->addChild("Comments",$addressObject->get_comments());

        $addressIndex += 1;

    }

echo $addressXML->asXML();

}

which outputs:-

<addresslist resultcount="2">
    <address id="0">
        <pickup>ADDRESS 1</pickup>
        <dropoff>ADDRESS 2</dropoff>
        <bookingdatetime>16/04/2014 12:03:57</bookingdatetime>
        <car></car>
        <jbmessage></jbmessage>
        <zone>NO ZONE</zone>
        <customerfare>3.5</customerfare>
        <passname>TEST</passname>
        <cartype>CAR</cartype>
        <tel>12345678912</tel>
        <comments></comments>
    </address>
</addresslist>

What I need to do is pass this to a jQuery file so I can display the information in a jQGrid. How would it be possible to achieve this?

2

1 Answer 1

0

Instead of XML use JSON. It's natively supporten in JavaScript, is smaller and faster. To encode array/stdClass in PHP to JSON you can use json_encode

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.