Android Question xml2Map Parsing Error ?

Kriter

New Member
Hi friends.
I am using the xml2map library.

I get an error when I receive more than one key data with the same name.

This xml data contains offline messages from Openfire Group Chat.
incoming xml data:

<message type='groupchat' id='aacda' from='[email protected]/Guest_55f6b630dfe6fafd' to='[email protected]/Guest_ec6744f8fcabd148'><body>Room message text....</body><stanza-id xmlns='urn:xmpp:sid:0' id='74cecd0f-b3c0-44ad-acca-c882390a39ac' by='[email protected]'/><addresses xmlns='http://jabber.org/protocol/address'><address type='ofrom' jid='[email protected]'/></addresses><delay xmlns='urn:xmpp:delay' stamp='2024-05-01T21:53:16.067Z' from='[email protected]/Guest_55f6b630dfe6fafd'/></message><message type='groupchat' id='aacda' from='[email protected]/Guest_55f6b630dfe6fafd' to='[email protected]/Guest_ec6744f8fcabd148'><body>2th Room message text...</body><stanza-id xmlns='urn:xmpp:sid:0' id='10d94560-d830-4355-b63b-8dffd29591c0' by='[email protected]'/><addresses xmlns='http://jabber.org/protocol/address'><address type='ofrom' jid='[email protected]'/></addresses><delay xmlns='urn:xmpp:delay' stamp='2024-05-01T21:53:17.069Z' from='[email protected]/Guest_55f6b630dfe6fafd'/></message><message type='groupchat' id='aacda' from='[email protected]/Guest_55f6b630dfe6fafd' to='[email protected]/Guest_ec6744f8fcabd148'><body>3th Room message text..</body><stanza-id xmlns='urn:xmpp:sid:0' id='7b84aa0f-a0a7-4927-9ee7-a94643a2ef20' by='[email protected]'/><addresses xmlns='http://jabber.org/protocol/address'><address type='ofrom' jid='[email protected]'/></addresses><delay xmlns='urn:xmpp:delay' stamp='2024-05-01T21:53:18.636Z' from='[email protected]/Guest_55f6b630dfe6fafd'/></message>

Error Msg:

xml2map_parse2 (java line: 191)
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 201: junk after document element
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:519)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:478)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at b4a.example.xml2map._parse2(xml2map.java:191)
at b4a.example.xml2map._parse(xml2map.java:179)
at b4a.example.servis._x_newdata(servis.java:1120)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
java.lang.RuntimeException: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 201: junk after document element
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:258)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 201: junk after document element
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:519)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:478)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:316)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at b4a.example.xml2map._parse2(xml2map.java:191)


Anyone have any ideas?
 

TILogistic

Expert
Licensed User
Longtime User
They are individual XML messages, you must group them

EDIT: sample:
B4X:
    Dim textxml As String = $"
    <messages>
    <message type='groupchat' id='aacda' from='[email protected]/Guest_55f6b630dfe6fafd' to='[email protected]/Guest_ec6744f8fcabd148'>
        <body>Room message text....</body>
        <stanza-id
            xmlns='urn:xmpp:sid:0' id='74cecd0f-b3c0-44ad-acca-c882390a39ac' by='[email protected]'/>
            <addresses
                xmlns='http://jabber.org/protocol/address'>
                <address type='ofrom' jid='[email protected]'/>
            </addresses>
            <delay
                xmlns='urn:xmpp:delay' stamp='2024-05-01T21:53:16.067Z' from='[email protected]/Guest_55f6b630dfe6fafd'/>
            </message>
            <message type='groupchat' id='aacda' from='[email protected]/Guest_55f6b630dfe6fafd' to='[email protected]/Guest_ec6744f8fcabd148'>
                <body>2th Room message text...</body>
                <stanza-id
                    xmlns='urn:xmpp:sid:0' id='10d94560-d830-4355-b63b-8dffd29591c0' by='[email protected]'/>
                    <addresses
                        xmlns='http://jabber.org/protocol/address'>
                        <address type='ofrom' jid='[email protected]'/>
                    </addresses>
                    <delay
                        xmlns='urn:xmpp:delay' stamp='2024-05-01T21:53:17.069Z' from='[email protected]/Guest_55f6b630dfe6fafd'/>
                    </message>
                    <message type='groupchat' id='aacda' from='[email protected]/Guest_55f6b630dfe6fafd' to='[email protected]/Guest_ec6744f8fcabd148'>
                        <body>3th Room message text..</body>
                        <stanza-id
                            xmlns='urn:xmpp:sid:0' id='7b84aa0f-a0a7-4927-9ee7-a94643a2ef20' by='[email protected]'/>
                            <addresses
                                xmlns='http://jabber.org/protocol/address'>
                                <address type='ofrom' jid='[email protected]'/>
                            </addresses>
                            <delay
                                xmlns='urn:xmpp:delay' stamp='2024-05-01T21:53:18.636Z' from='[email protected]/Guest_55f6b630dfe6fafd'/>
                            </message>
                        </messages>
        "$
        
    Dim ParseXML As Xml2Map
    ParseXML.Initialize
    Dim MapXml As Map = ParseXML.Parse(textxml)
    
    Log(MapXml.As(JSON).ToCompactString)
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
or
B4X:
    Dim ParseXML As Xml2Map
    ParseXML.Initialize
    ParseXML.StripNamespaces = True
    Dim MapXml As Map = ParseXML.Parse(textxml)
    
    Log(MapXml.As(JSON).ToCompactString)
 
Upvote 0
Top