How to parse JAXLXml (XMPPStanza)?

101 views
Skip to first unread message

Seshachalam Malisetti

unread,
Jan 19, 2014, 7:17:55 AM1/19/14
to ja...@googlegroups.com
I am using the JAXL library to connect to google gcm ccs server. I am receiving the upstream messages sent by the application. I have a problem parsing the file. The receive message callback( 'on_normal_message' ) gives the XMPPStanza object to callback. I need to parse this object to get the actual message sent by the mobile app. The below is my XMPPStanza.

    XMPPStanza Object
(
    [xml:XMPPStanza:private] => JAXLXml Object
        (
            [name] => message
            [ns] => jabber:client
            [attrs] => Array
                (
                    [to] => I...@gcm.googleapis.com
                    [from] => dev...@gcm.googleapis.com
                    [type] => normal
                )

            [text] =>
            [childrens] => Array
                (
                    [0] => JAXLXml Object
                        (
                            [name] => gcm
                            [ns] => google:mobile:data
                            [attrs] => Array
                                (
                                )

                            [text] => {
                            "category":"com.google.android.gcm.demo.app","

                            data":{"my_message":"Hello World","my_action":"com.google.android.gcm.demo.app.ECHO_NOW"},

                            "message_id":"2",

                            "from":"GCMID"
                            }
                            [childrens] => Array
                                (
                                )

                            [parent] => JAXLXml Object
 *RECURSION*
                            [rover] => JAXLXml Object
 *RECURSION*
                        )

                )

            [parent] =>
            [rover] => JAXLXml Object
 *RECURSION*
        )

)


The data that is required by me is in [childrens]. Its an array of JAXLXml objects. How do i get the [text] of this children. This is actually a json string. I am not able to json_decode this string because of the """. How do I get this data easily ? I have to create a ack message to send to the ccs server after receiving the messages. I need from, message_id fileds in the original message.

Thanks,
abbiya

Abhinav Singh

unread,
Jan 19, 2014, 7:56:27 AM1/19/14
to ja...@googlegroups.com
After you extract the required text node (read http://abhinavsingh.com/blog/2012/09/jaxlxml-strophe-style-xml-builder-working-with-jaxl-a-networking-library-in-php-part-2/ for how to), use html_entity_decode like this:

    $ php -r 'echo html_entity_decode("{
                                "category":"com.google.android.gcm.demo.app","
    
                                data":{"my_message":"Hello World","my_action":"com.google.android.gcm.demo.app.ECHO_NOW"},
    
                                "message_id":"2",
    
                                "from":"GCMID"
                                }");'
    {
                                "category":"com.google.android.gcm.demo.app","
    
                                data":{"my_message":"Hello World","my_action":"com.google.android.gcm.demo.app.ECHO_NOW"},
    
                                "message_id":"2",
    
                                "from":"GCMID"

abbiya

unread,
Jan 19, 2014, 8:07:52 AM1/19/14
to ja...@googlegroups.com
Thanks abhinav

 abbiya
Seshachalam M
via Hop

In reply to:
After you extract the required text node (read http://abhinavsingh.com/blog/2012/09/jaxlxml-strophe-style-xml-builder-working-with-jaxl-a-networking-library-in-php-part-2/ for how to), use html_entity_decode like this:

    $ php -r 'echo html_entity_decode("{
                                "category":"com.google.android.gcm.demo.app","

                                data":{"my_message":"Hello World","my_action":"com.google.android.gcm.demo.app.ECHO_NOW"},

                                "message_id":"2",

                                "from":"GCMID"
                                }");'
    {
                                "category":"com.google.android.gcm.demo.app","

shivam bhusri

unread,
Jul 24, 2016, 2:29:09 PM7/24/16
to jaxl, abb...@gmail.com
Sir,I had read all the docs but could not be able to parse jaxlxml.I am working on fcm chat app and require to parse jaxlxml sent by server.can you please provide a small example on how to parse jaxlxml.It would be a huge help.
Reply all
Reply to author
Forward
0 new messages