Mailbag
Typically in Bots you need to configure what editype and messagetype for each input file it will be processing in your translations. This can become tedious for well defined EDI types like X12, EDIFACT, TRADACOMS, and XML files especially when all different types come in through the same channel.
This is where the mailbag comes in. Bots can automatically determine the editype and messagetype with no to little configuration depending on the type.
X12, EDIFACT, TRADACOM files
For X12, EDIFACT, and TRADACOMS files, just configure editype=mailbag and messagetype=mailbag on the translation and Bots will figure out the rest.
XML files
For XML files, even though they are structured files, they are usually a custom standard developed by your trading partner (unless they are CXML) so they require one more step. You need to tell Bots how the different XML files map to each messagetype.
You still configure editype=mailbag and messagetype=mailbag on the translation but you also need to create a mailbag.py in bots/usersys/grammars/xml and configure each XML file type. Bots uses XPath expressions for parsing the XML.
For child tag or content based types
If the type of XML file is defined from a child tag or content, use this syntax.
mailbagsearch = [
{'xpath': 'envelope', 'messagetype': 'bagger'},
{'xpath': 'message/type', 'content': 'invoice', 'messagetype': 'invoic'},
{'xpath': 'message/type2', 'messagetype': 'invoic'},
{'xpath': 'message/type', 'content': 'invoice3', 'messagetype': 'invoic3'},
]
Each dict is for a messagetype.
xpathis where Bots looks for a valuemessagetypeis the messagetype that bots will use when:If dict contains no
content, it matches ifxpathreturns any valueIf dict contains
content, it matches if the result ofxpathis equal tocontent
Example 1: Child Tag / With No Content
It matches if document/envelope exists and contains any value.
<?xml version="1.0" encoding="utf-8" ?>
<document>
<envelope>
<partnerid>1234</partnerid>
</envelope>
</document>
Example 2: With Content
It matches if document/message/type exists and contains the value invoice.
<?xml version="1.0" encoding="utf-8" ?>
<document>
<message>
<type>invoice</type>
</message>
</document>
For XML root tag based types
If the type is defined by the root XML tag, use this syntax.
mailbagsearch = [
{'xpath':'.','tag':'PurchaseOrder','messagetype':'purchaseorder'},
{'xpath':'.','tag':'Acknowledgment','messagetype':'acknowledgement'},
]
The . for xpath means the root element.
Example
PurchaseOrder
<?xml version="1.0" encoding="utf-8" ?>
<PurchaseOrder>
<Header>
<TradingPartner>1234</TradingPartner>
</Header>
</PurchaseOrder>
Acknowledgment
<?xml version="1.0" encoding="utf-8" ?>
<Acknowledgment>
<Header>
<TradingPartner>1234</TradingPartner>
</Header>
</Acknowledgment>