0

XML Converter

  • updated 3 yrs ago

Description

This part allows you to convert XML to LUA or LUA to XML. Within the context of a LogicNets-based application data is stored in a LUA format, and there are times when the system receives external C. Sometimes external data is received in other formats like XML. This part can convert LUA to XML and XML to LUA.

XML language components and LUA language components (similar to JSON) do not match completely. XML has elements, element attributes, and element values; for example, <element attribute=”attribute_value”>element-value</element>. In XML, elements can be nested and multiple elements with the same element name can exist on the same level. In LUA, however, data objects have names and values and can be nested, but multiple data objects with the same name on the same level is not possible. LUA supports arrays instead.

When the system finds a single element in XML it can convert it to a single value in LUA or to a collection with one entry. There is no LUA language construction for XML attributes. To support two-way conversion (XML to LUA and back to XML again) the outputted LUA structure contains additional levels to capture all information. 

@<attribute-name> = <attribute-value> 

#text = <element-value> 

#index = <element position in the parent element> 

XML 

LUA 

<e name="value">text e</e> 

e = {

{ ["@name"] = "value", ["#text"] = "text e", ["#index"] = 1 } 

}

<e> 

<a>text a</a> 

<b>text b</b> 

</e> 

e = {

["#index"] = 1, 

a = { { ["#text"] = "text a", ["#index"] = 1 } }, 

b = { { ["#text"] = "text b", ["#index"] = 2 } } 

<e> 

<a>text a1</a> 

<a>text a2</a> 

</e> 

e = {

["#index"] = 1, 

a = {

{ ["#text"] = "text a1", ["#index"] = 1 },

{ ["#text"] = "text a2", ["#index"] = 2 } 

There are also situations in which the XML does not contain any attributes or when the system can ignore the attributes. For these cases, the part also supports simplification mode. In this mode, the system ignores all XML attributes, stores the element value as a single value (no collection) if no elements with the same name occur on the same level, and does not store the position of elements in the XML in LUA. 

XML 

LUA 

<e name="value">text e</e> 

e = “text e” 

<e> 

<a>text a</a> 

<b>text b</b> 

</e> 

e = {

a = “text a”, 

b = “text b” 

<e> 

<a>text a1</a> 

<a>text a2</a> 

</e> 

e = {

a = { “text a1”, “text a2” } 

Simplified LUA structures cannot be converted back to XML. 

Editor Fields

Configure this part using the following fields:

Tab 

Field Name 

Description/Use

Type 

Mandatory/Optional 

Basic 

Mode 

This is the mode for the conversion: XML to LUA | LUA to XML 

Dropdown

Mandatory

Basic 

Input text 

This is the (XML to LUA) XML input.

Text 

Mandatory

Basic 

Input Object 

This is the (LUA to XML) LUA input object.

Object 

Mandatory

Basic 

Output Object 

This is the path where the system stores the result.

Object 

Mandatory

Basic 

Error Object 

This is the path where the system stores the conversion errors.

Object 

Optional

Basic 

Lower case element names 

For XML to LUA, if you set this to Yes the system makes lower case all element names.

Y|N 

Optional

Basic 

Lower case attribute names 

For XML to LUA, if you set this to Yes the system makes all XML attribute names lower case.

Y|N 

Optional

Basic 

Simplify 

For XML to LUA, if you set this to Yes the system outputs a simplified LUA structure.

Y|N 

Optional

Basic 

Element label attribute 

If you set Simplify to Yes and specify a value in this field the system uses this as the LUA data object name instead of the XML element name.

Text 

Optional

Basic 

Indentation 

For LUA to XML, this is the indentation text.

Text 

Optional

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 3 yrs agoLast active
  • 17Views
  • 2 Following

Home