XML
Last updated
Last updated
Javascript "compatible" representation is expressed using lists and js objects, where each js object has special attributes named: "tagName", "tagValue" and "subTags".
The document (list of tags) is expressed as a list of js objects, where each js object can have a list of subtags and attributes, expressed object's attributes. The js object always contains special entries named "tagName", "subTags" and optionally "tagValue" if there is tag value.
Syntax
Details
Returns an XML representation, expressed as a list of Javascript objects, where each of them has three special attributes: "tagName", "tagValue" and "subTags". You can then navigate through this js object and extract any data.
Example
(i.e. after invoking parseXML method)
Syntax
Details
Example
JohnDoe...
JaneRoe...
(i.e. after invoking parseXML and findTagNames methods)
For each selected node, a new js object will be created and it will have as many attributes as the ones specified through tagNames argument, whose values will be retrieved by as sub tags values.
Syntax
Details
Example
JohnDoe...
JaneRoe...
will return a list of js objects having this structure:
[{ "firstname": "John", "lastname": ... }, { "firstname": "Jane", ...}]
Platform embeds the Java standard XSLT transformer, through which you can convert data contained in an XML file to an HTML document, using an XSL file describing the layout of the HTML document and how to show data coming from the XML.
Basically, this feature uses XML + XSL to produce HTML
Syntax
Details
Note: if the resulting HTML file seems empty (contains only CSS content but not data), it is likely that the XSL definition requires a strong validation; in such a scenario, set both "namespaceAware" and "validating" to true.
Platform provides a server-side javascript method you can use to convert a JSON content to an XML document. This method does not support attributes generation within an XML tag. The mapping between the input javascript object and the final XML document follows these rules:
Syntax
Details
The argument "settings" can contain a variety of different attributes, according to the specific scenario:
toUpperCase: optional flag having values true|false convert the attribute names in upper case when creating XML tags
xsd: optional string representing the relative path, within the web context, where finding the .xsd file for the XMKL document to generate; tags order is defined starting from the sequence defined in the xsd file
xsdValidation: optional true|false; ignored if "xsd" has not been specified; default value: false
tabSpaces: optional int number of spaces to add for each nested tag; if not specified, it is set to 2
dateFormat: optional string representing the date format for a Date object; if not specified, its default value is "yyyy-MM-dd"
decimalFormat: optional string representing the numeric format for a number; if not specified, its default value is "#.00"
attributesToConvertToDate: javascript Array of attribute names to convert to dates; each of them must be expressed as "yyyy-MM-dd HH:mm:ss" or "yyyy-MM-dd" (i.e. JSON standard Platform dates) and will be converted in strings having "dateFormat" format
tagSequence: optional map representing for each tag, the ordered list of subtags; e.g. { TAG1: ["TAG2","TAG3"], ... }
Note: either "settings.tagSequence" or "settings.xsd" must be specified, in order to get the right order for the tags. If an XSD file is specified, it can be used to automatically retrieve the sequence of sub-tags for each tag, since the order is part of the XSD definition. Otherwise, it must be specified ,manually, through the tagSequence attribute.
Example
In this example there is a direct mapping between a simple javascript object and tags of the generated XML document, except for the input attribute named "ragSoc", converted to the "rag" tag name:
The resulting XML document would be:
The settings's attribute "tagSequence" is needed to provide the right sequence for <r> tag's sub-tags.
Example
This is a more complex example, where there is a list of sub-tags combined with another sub-tag, all children of the same tag. The sub-tags sequence is defined, starting from the XSD definition.
Please note the Date management: in case the javascript object provided in input does NOT contain Javascript Date objects, it is needed to correctly (i) parse them in input and (ii) format them in output, within the XML document. Both operations can be carried out through the optional setting "attributesToConvertToDate", which contain a list of input attributes expressed as String and always in the format "yyyy-MM-dd" or "yyyy-MM-dd HH:mm:ss". This is the string format managed internally by Platform (e.g. executeQuery, etc.) and can be used as the starting point. Once this string values have been converted to Date objects, they can be converted to the final String format, using the "dateFormat" attribute.
Argument
Description
xmlDocument
an XML document as a String
Argument
Description
xmlDocNodes
XML document parsed through parseXML method
path
a tags path, expressed as tag1/tag2/tag3...
Argument
Description
selectedNodes
nodes to analyze
tagNames
list of tag names to compare with each subtag of each selected node.
Argument
Description
xmlDirId
directory id where the XML data file is located
xmlFileName
XML data file name, stored in the xmlDirId
xlsDirId
directory id where the stylesheet XSL file is located
xlsFileName
XLS file, used to define ther layout for the HTML file to generate
htmlDirId
directory id where the HTML will be generated
htmlFileName
HTML file name to generate
namespaceAware
true or false; defines whether the namespace must be checkd; if in dubt, set it to true
validating
true or false; defines whether the XML must be validated with respect to the XSL file; if in dubt, set it to true
Input data
XML element
"header" argument
optional header tag, something like <?xml version='1.0' encoding='UTF-8'?>
"rootNode" argument
the root XML node, something like <maintag> ... </maintag>
"jsonObj" argument: represents the javascript object to convert to XML, composed of attributes, which can be filled with "primitive" values, like numbers or text; e.g.
{ orderNum: 1 }
each attribute in jsonObj is converted to a tag, whose value is the tag value; e.g. <orderNum>1</orderNum>
"jsonObj" argument: represents the javascript object to convert to XML, composed of attributes, which can contain inner objects; e.g.
{ customer: { name: "John", surname: "Smith" } }
<customer>
<name>John</name>
<surname>Smith</surname>
</customer>
"jsonObj" argument: represents the javascript object to convert to XML, composed of attributes, which can be contain a list of objects ; e.g.
{ rows: [
{ description: "Article1", price: 123 },
{ description: "Article2", price: 456 }
]}
A JSON notation is not able alone to define how to manage a list of subtags: an additional tag is needed for each element in list and can be defined through the "listMapping" argument; e.g.
listMapping: { rows: "row" }
<rows>
<row> <description>Article1</description><price>123</price>
</row>
<row><description>Article2</description><price>456</price>
</row>
</rows>
in a javascript object the attributes order is not important, but the corresponding tags order is important in an XML document. Tags order is defined through the "settings.tagSequence" or "settings.xsd" properties
sub-tags order is defined starting from the attribute order specified either in the tagSequence property or through the xsd content
Argument
Description
jsonObj
javascript object to convert; see examples below
header
string representing the XML header; can be null
rootNode
string representing the root XML node, expressed as <tagname>
dirId
directory id where saving the XML document
fileName
file name to use for the XML document to save
attrMapping
mapping between attribute names and tags, expressed as a javascript object; can be null; if not specified or if an attribute has not been found in the mapping, the corresponding tag is converted as it is; e.g.
{ tag1: "value1" } ---> <tag1>value1</tag1>
If a mapping is specified for tag1, then it is used for naming the tag; e.g.
attrMapping: { tag1: "TAG_ONE"}
{ tag1: "value1" } ---> <TAG_ONE>value1</TAG_ONE>
listMapping
mapping between an attribute having a list of values and the tag name to use to identify each element of the list; can be null
settings
additional settings; CANNOT be null; see below for more details