xmpp : How to read nested array data from xml using stanza.io

251 Views Asked by At

I am receiving a stanza like this:

<message xmlns='jabber:client' to='1' from='2' type='chat' id='50c1d830-283c-11e8-9dcf' xmlns='jabber:client'>
  <system xmlns='urn:xmpp:type' layout='layout1' default='true' subType='alert'>
    <title>First User</title>
    <email>[email protected]</email>
    <action_label>Contact us</action_label>
    <deeplinks>
            <deeplink>
                <label>My deals</label>
                <link>/home</link>
            </deeplink>
            <deeplink>
                <label>New deals</label>
                <link>/page</link>
            </deeplink>
        </deeplinks>
  </system>
  <body>[This is a system message]</body>
</message>

From this, I can read the type as system and its attribute like title, email, action_label, layout, subType, default attributes

const system = stanzas.define({
        name: 'system',
        element: 'system',
        topLevel: true,
        namespace: 'urn:xmpp:type',
        fields: {
            layout: stanzas.utils.attribute('layout'),
            default: stanzas.utils.attribute('default'),
            subType: stanzas.utils.attribute('subType'),
            email: stanzas.utils.textSub('urn:xmpp:type', 'email'),
            actionLabel: stanzas.utils.textSub('urn:xmpp:type', 'action_label'),
            title: stanzas.utils.textSub('urn:xmpp:type', 'title')
        }
    });
stanzas.withMessage(Message => {
    stanzas.extend(Message, system);
});

But I am not able to read the nested deeplink stanza. Any suggestions how I can parse that data?

0

There are 0 best solutions below