Event/Alien2XML definition
From PlcWiki
(→Other special features) |
|||
(14 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
- | Device events have prefix '''<code>workplace.device.<name>.event.</code>''' while alien2xml node definitions have prefix '''<code>node.</code>''' | + | Device events have a prefix '''<code>workplace.device.<name>.event.</code>''' while alien2xml node definitions have a prefix '''<code>node.</code>''' |
=Examples= | =Examples= | ||
Example (alien2xml): | Example (alien2xml): | ||
- | + | <pre> | |
+ | <nowiki> | ||
+ | targetService = dbus2dirq | ||
+ | |||
+ | rootNode = product | ||
+ | |||
node.product = .* | node.product = .* | ||
- | node.product. | + | node.product.version = 1.0 |
- | node.product. | + | node.product.version.order = 1 |
- | node.product. | + | node.product.md5sum = <internal:md5sum> |
- | node.product.header = <node:header=[[:]]> | + | node.product.md5sum.order = 2 |
- | node.product. | + | node.product.status = imported |
- | node.product. | + | node.product.status.order = 3 |
+ | node.product.header = <node:header=[[0:95]]> | ||
+ | node.product.header.order = 4 | ||
+ | node.product.parts = <node:parts=[[95:]]> | ||
+ | node.product.parts.order = 5 | ||
node.header = .* | node.header = .* | ||
- | node.header. | + | node.header.id = [[0:15]] |
- | + | node.header.id.pattern.1 = " +$" | |
+ | node.header.id.replace.1 = "" | ||
+ | node.header.model = [[15:6]] | ||
+ | node.header.model.pattern.1 = " +$" | ||
+ | node.header.model.replace.1 = "" | ||
+ | node.header.productionYear = [[21:4]] | ||
+ | node.header.custSequence = [[25:11]] | ||
+ | node.header.custSequence.pattern.1 = "^0+" | ||
+ | node.header.custSequence.replace.1 = "" | ||
+ | node.header.lineCustomer = [[36:2]] | ||
+ | node.header.fCode = [[38:20]] | ||
+ | node.header.ownCarNumber = [[58:7]] | ||
+ | node.header.ownCarNumber.pattern.1 = "^0+" | ||
+ | node.header.ownCarNumber.replace.1 = "" | ||
+ | node.header.lineInternal = [[65:2]] | ||
+ | node.header.ownSequence = [[67:5]] | ||
+ | node.header.ownSequence.pattern.1 = "^0+" | ||
+ | node.header.ownSequence.replace.1 = "" | ||
+ | node.header.company = [[72:3]] | ||
+ | node.header.plant = [[75:3]] | ||
+ | node.header.vin = [[78:17]] | ||
+ | node.header.vin.pattern.1 = " +$" | ||
+ | node.header.vin.replace.1 = "" | ||
+ | |||
+ | node.parts = .* | ||
+ | node.parts.part = [[:]] | ||
+ | node.parts.part.list_member = ".{19}" | ||
+ | node.parts.part.regex = "(.*[^ ]) *" | ||
+ | |||
+ | Debug = true | ||
+ | </nowiki> | ||
+ | </pre> | ||
Example input: | Example input: | ||
- | + | 0913VWPO010 POLO 200900000008584032000110101100010003000098550300111010000VW POLO CUST TEST 02 CUST-BOM100 CUST-T-0815 CUST-T-4712 CUST-TEST07 | |
Example output: | Example output: | ||
- | + | <!DOCTYPE product> | |
- | + | <product> | |
+ | <version>1.0</version> | ||
+ | <md5sum>9790ca185475123b074c2c83bc522172</md5sum> | ||
+ | <status>imported</status> | ||
<header> | <header> | ||
- | + | <company>010</company> | |
+ | <custsequence>8584</custsequence> | ||
+ | <fcode>20001101011000100030</fcode> | ||
+ | <id>0913VWPO010</id> | ||
+ | <linecustomer>03</linecustomer> | ||
+ | <lineinternal>03</lineinternal> | ||
+ | <model>POLO</model> | ||
+ | <owncarnumber>9855</owncarnumber> | ||
+ | <ownsequence>111</ownsequence> | ||
+ | <plant>000</plant> | ||
+ | <productionyear>2009</productionyear> | ||
+ | <vin>VW POLO</vin> | ||
</header> | </header> | ||
- | < | + | <parts> |
- | + | <part>CUST TEST 02</part> | |
- | + | <part>CUST-BOM100</part> | |
- | + | <part>CUST-T-0815</part> | |
+ | <part>CUST-T-4712</part> | ||
+ | <part>CUST-TEST07</part> | ||
+ | </parts> | ||
+ | </product> | ||
=Node/Event= | =Node/Event= | ||
Line 47: | Line 105: | ||
Input substring expression defines a substring of original input (or input reduced by any regex group definitions). Omitted '''<code>from</code>''' means index 0, omitted '''<code>length</code>''' means the rest of the input. | Input substring expression defines a substring of original input (or input reduced by any regex group definitions). Omitted '''<code>from</code>''' means index 0, omitted '''<code>length</code>''' means the rest of the input. | ||
- | When '''<code><node:_subnode_=_text_></code>''' is used as a value, it tells alien2xml processor that this property is a subnode and should be expanded by using appropriate '''<code>node._subnode_</code>''' definition while using _text_ as the input. | + | |
+ | When '''<code><node:_subnode_=_text_></code>''' is used as a value, it tells alien2xml processor that this property is a subnode and should be expanded by using appropriate '''<code>node._subnode_</code>''' definition while using '''<code>_text_</code>''' as the input. | ||
+ | |||
+ | |||
+ | When an item | ||
+ | node.<node_name>.<property_name>.list_member = <regex> | ||
+ | is present in the definition, the property is considered to be a list of values. | ||
+ | For PLC Device events it means the list members have keys '''<code><property_name>[_index_]</code>''' where '''<code>_index_</code>''' is a zero-based autoincremented integer. | ||
+ | On the other hand, Alien2XML generates multiple subelements with the same name '''<code><property_name></code>'''. | ||
+ | The input (or reduced input) is searched for any occurrences of '''<code><regex></code>''' - each matched substring is then used as the content of single list member. If there is a regex group present in '''<code><regex></code>''' the list member content is reduced to appropriate group match. | ||
+ | |||
When an item | When an item | ||
node.<node_name>.<property_name>.regex = <regex> | node.<node_name>.<property_name>.regex = <regex> | ||
is present in the definition, it means the above value is assigned to property only if the input matches the regex '''<code><regex></code>''', otherwise it is assigned an empty value. Additionally, the current input is further reduced to any regex group if present (only for the purpose of assigning to that property). | is present in the definition, it means the above value is assigned to property only if the input matches the regex '''<code><regex></code>''', otherwise it is assigned an empty value. Additionally, the current input is further reduced to any regex group if present (only for the purpose of assigning to that property). | ||
- | |||
=Other special features= | =Other special features= | ||
Line 58: | Line 125: | ||
node.product.item1.translate.word = slovo | node.product.item1.translate.word = slovo | ||
- | node.product.item2.pattern. | + | Content substring replacement: |
- | node.product.item2.replace. | + | node.product.item2.pattern.1st_rule = "to\s*be\s*replaced" |
+ | node.product.item2.replace.1st_rule = replacement | ||
+ | node.product.item2.pattern.2nd_rule = "this\s*should\s*be\s*replaced as well" | ||
+ | node.product.item2.replace.2nd_rule = replacement2 | ||
+ | |||
+ | Enforcing element order in generated XML: | ||
+ | node.product.item1.order = 1 | ||
+ | node.product.item2.order = 2 | ||
+ | |||
+ | Internal alien2xml variables can be referred to as follows: | ||
+ | node.product.m5sum = <internal:md5sum> | ||
+ | |||
+ | As of now, these internal variables are available: | ||
+ | |||
+ | {| border="1" | ||
+ | |+ '''Internal variables''' | ||
+ | |- | ||
+ | | <code>md5sum</code> || MD5 sum of input | ||
+ | |- | ||
+ | | <code>now</code> || Current date and time in format <code>yyyy-MM-dd hh:mm:ss.zzz</code> | ||
+ | |- | ||
+ | | <code>timestamp</code> || miliseconds since epoch | ||
+ | |- | ||
+ | | <code>service</code> || Name of Alien2XML service | ||
+ | |- | ||
+ | | <code>target_service</code> || Name of the target service | ||
+ | |- | ||
+ | | <code>passed_caller</code> || Caller id passed in this request | ||
+ | |- | ||
+ | | <code>passed_id</code> || Message ID passed in this request | ||
+ | |} |
Current revision as of 10:21, 19 May 2011
Device events have a prefix workplace.device.<name>.event.
while alien2xml node definitions have a prefix node.
Contents |
Examples
Example (alien2xml):
targetService = dbus2dirq rootNode = product node.product = .* node.product.version = 1.0 node.product.version.order = 1 node.product.md5sum = <internal:md5sum> node.product.md5sum.order = 2 node.product.status = imported node.product.status.order = 3 node.product.header = <node:header=[[0:95]]> node.product.header.order = 4 node.product.parts = <node:parts=[[95:]]> node.product.parts.order = 5 node.header = .* node.header.id = [[0:15]] node.header.id.pattern.1 = " +$" node.header.id.replace.1 = "" node.header.model = [[15:6]] node.header.model.pattern.1 = " +$" node.header.model.replace.1 = "" node.header.productionYear = [[21:4]] node.header.custSequence = [[25:11]] node.header.custSequence.pattern.1 = "^0+" node.header.custSequence.replace.1 = "" node.header.lineCustomer = [[36:2]] node.header.fCode = [[38:20]] node.header.ownCarNumber = [[58:7]] node.header.ownCarNumber.pattern.1 = "^0+" node.header.ownCarNumber.replace.1 = "" node.header.lineInternal = [[65:2]] node.header.ownSequence = [[67:5]] node.header.ownSequence.pattern.1 = "^0+" node.header.ownSequence.replace.1 = "" node.header.company = [[72:3]] node.header.plant = [[75:3]] node.header.vin = [[78:17]] node.header.vin.pattern.1 = " +$" node.header.vin.replace.1 = "" node.parts = .* node.parts.part = [[:]] node.parts.part.list_member = ".{19}" node.parts.part.regex = "(.*[^ ]) *" Debug = true
Example input:
0913VWPO010 POLO 200900000008584032000110101100010003000098550300111010000VW POLO CUST TEST 02 CUST-BOM100 CUST-T-0815 CUST-T-4712 CUST-TEST07
Example output:
<!DOCTYPE product> <product> <version>1.0</version> <md5sum>9790ca185475123b074c2c83bc522172</md5sum> <status>imported</status> <header> <company>010</company> <custsequence>8584</custsequence> <fcode>20001101011000100030</fcode> <id>0913VWPO010</id> <linecustomer>03</linecustomer> <lineinternal>03</lineinternal> <model>POLO</model> <owncarnumber>9855</owncarnumber> <ownsequence>111</ownsequence> <plant>000</plant> <productionyear>2009</productionyear> <vin>VW POLO</vin> </header> <parts> <part>CUST TEST 02</part> <part>CUST-BOM100</part> <part>CUST-T-0815</part> <part>CUST-T-4712</part> <part>CUST-TEST07</part> </parts> </product>
Node/Event
The first condition for node (or event) to be created is this:
node.<node_name> = <regex>
If the input (alien input or raw device input) doesn't match the regex, any other definition rules are ignored and an empty XML element node_name
(or no event) is generated.
If the regex contains a group (enclosed in a parenthesis pair), the whole input is reduced to this group substring for later processing.
Properties
The node (or event) can contain any number of properties (these properties appear as subelements in alien2xml output). The definition of a property is as follows:
node.<node_name>.<property_name> = _text_
or
node.<node_name>.<property_name> = <node:_subnode_=_text_>
where _text_
is a text constant with any number of [[from:length]]
input substring expressions.
Input substring expression defines a substring of original input (or input reduced by any regex group definitions). Omitted from
means index 0, omitted length
means the rest of the input.
When <node:_subnode_=_text_>
is used as a value, it tells alien2xml processor that this property is a subnode and should be expanded by using appropriate node._subnode_
definition while using _text_
as the input.
When an item
node.<node_name>.<property_name>.list_member = <regex>
is present in the definition, the property is considered to be a list of values.
For PLC Device events it means the list members have keys <property_name>[_index_]
where _index_
is a zero-based autoincremented integer.
On the other hand, Alien2XML generates multiple subelements with the same name <property_name>
.
The input (or reduced input) is searched for any occurrences of <regex>
- each matched substring is then used as the content of single list member. If there is a regex group present in <regex>
the list member content is reduced to appropriate group match.
When an item
node.<node_name>.<property_name>.regex = <regex>
is present in the definition, it means the above value is assigned to property only if the input matches the regex <regex>
, otherwise it is assigned an empty value. Additionally, the current input is further reduced to any regex group if present (only for the purpose of assigning to that property).
Other special features
node.product.item1.translate.word = slovo
Content substring replacement:
node.product.item2.pattern.1st_rule = "to\s*be\s*replaced" node.product.item2.replace.1st_rule = replacement node.product.item2.pattern.2nd_rule = "this\s*should\s*be\s*replaced as well" node.product.item2.replace.2nd_rule = replacement2
Enforcing element order in generated XML:
node.product.item1.order = 1 node.product.item2.order = 2
Internal alien2xml variables can be referred to as follows:
node.product.m5sum = <internal:md5sum>
As of now, these internal variables are available:
md5sum | MD5 sum of input |
now | Current date and time in format yyyy-MM-dd hh:mm:ss.zzz
|
timestamp | miliseconds since epoch |
service | Name of Alien2XML service |
target_service | Name of the target service |
passed_caller | Caller id passed in this request |
passed_id | Message ID passed in this request |