Having issues with XML File

38 views
Skip to first unread message

Lee Pedley

unread,
Oct 26, 2022, 7:57:37 AM10/26/22
to Bots Open Source EDI Translator
Hi,

I am still having issues with getting an XML element into the right place and wondered if anyone could help.

I know Henk has mentioned this has been asked many times but from checking the forum I don't think this answers my current predicament and was wondering if anyone on here may have had the same issue.

The XML which I am trying to create structures a child node below another. So what I am looking to do is move the user agent node below the Identity.  At the moment it seems to form the node as follows;

<Sender>
       <UserAgent>Agent</UserAgent>
       <Credential domain="domain"><Identity>ID</Identity>.   
       </Credential>
</Sender>

But what I want to get is this;

<Sender>
       <Credential domain="domain"><Identity>ID</Identity>.   
       </Credential>
       <UserAgent>Agent</UserAgent>
</Sender>

Now the mapping is 

structure = [

{ID:'cXML',MIN:0,MAX:99999,LEVEL:[

    {ID:'Header',MIN:0,MAX:99999,LEVEL:[

        {ID:'Sender',MIN:0,MAX:99999,LEVEL:[

            {ID:'Credential',MIN:0,MAX:99999},

        ]},

    ]},

]},


'Credential':

    [

    ['BOTSID', 'M', 256, 'AN'],

    ['Credential__domain', 'C', 256, 'AN'],

    ['Identity', 'C', 256, 'AN'],

    ],

'Sender':

    [

    ['BOTSID', 'M', 256, 'AN'],

    ['UserAgent', 'C', 256, 'AN'],

    ],

So when I use the mapping

out.put({'BOTSID':'cXML'},{'BOTSID':'Header'},{'BOTSID':'Sender'},{'BOTSID':'Credential','Credential__domain':"domain"})

        out.put({'BOTSID':'cXML'},{'BOTSID':'Header'},{'BOTSID':'Sender'},{'BOTSID':'Credential','Identity':"ID"})

        out.put({'BOTSID':'cXML'},{'BOTSID':'Header'},{'BOTSID':'Sender','UserAgent':"Agent"})


It produces the first example where the UserAgent is above the Credential so not in the order I have it listed here.


I think because its calling the output directly to Sender bots is putting it directly under sender instead of below Credentials as it is formed in the mapping.


From testing it on another system it fails validation as the UserAgent isn't in the right location, and therefore requires me to move the user agent down below credentials.  

Surely other people have had the same issue, and if so what did you do to correct the issue?


Thanks


Lee

Message has been deleted

KenyonIT

unread,
Nov 3, 2022, 5:54:53 PM11/3/22
to Bots Open Source EDI Translator
Hi Lee,

You can create recorddefs using BOTSCONTENT, like so:

GRAMMAR

from bots.botsconfig import *


structure = [
{ID:'cXML',MIN:0,MAX:99999,LEVEL:[
    {ID:'Header',MIN:0,MAX:99999,LEVEL:[
        {ID:'Sender',MIN:0,MAX:99999,LEVEL:[
            {ID:'Credential',MIN:0,MAX:99999},
            {ID:'UserAgent',MIN:0,MAX:99999},
        ]},
    ]},
]},
]

recorddefs = {
'cXML':

    [
    ['BOTSID', 'M', 256, 'AN'],
    ],

'Credential':
    [
    ['BOTSID', 'M', 256, 'AN'],
    ['Credential__domain', 'C', 256, 'AN'],
    ['Identity', 'C', 256, 'AN'],
    ],
'Header':

    [
    ['BOTSID', 'M', 256, 'AN'],
    ],
'Sender':
    [
    ['BOTSID', 'M', 256, 'AN'],
    ['UserAgent', 'C', 256, 'AN'],
    ],
'UserAgent':

    [
    ['BOTSID', 'M', 256, 'AN'],
    ['BOTSCONTENT', 'C', 256, 'AN'],
    ],
}


MAPPING

def main(inn,out):

    out.put({'BOTSID':'cXML'},{'BOTSID':'Header'},{'BOTSID':'Sender'},{'BOTSID':'Credential','Credential__domain':"domain"})
    out.put({'BOTSID':'cXML'},{'BOTSID':'Header'},{'BOTSID':'Sender'},{'BOTSID':'Credential','Identity':"ID"})
    out.put({'BOTSID':'cXML'},{'BOTSID':'Header'},{'BOTSID':'Sender'},{'BOTSID':'UserAgent','BOTSCONTENT':"Agent"})
Reply all
Reply to author
Forward
0 new messages