XML Records

Stable Version 1.6.9 (O11)
Also available for 10, 9.1, 9.0, Older
Published on 18 Apr (4 weeks ago) by 
Stable Version 1.6.9 (O11)
Also available for 10, 9.1, 9.0, Older
Published on 18 Apr (4 weeks ago) by 
Created on 06 May 2010

XML Records

Documentation

Introduction

XMLRecords is an extension that allows you to convert OutSystems Records and RecordLists into XML and vice-versa. For implementation examples, check the Try Now link above.


Actions

This component provides 3 actions:

1. RecordListToXML 

This method allows you to convert a Record List into structured XML. You can add aliases to nodes through the AttributesConfig structure, as well as specifying a Namespace. Finally, you can force a wrapping node to the resulting output in order to have valid XML.


- Step 1: Create a Record list type variable 

Create a new variable of Record List type, that should be transformed into XML. Each Record attribute represents a XML attribute.

 - Step 2: Fill the created Record List type variable 

Fill the variable with the corresponding values to put in each XML attribute. You can assign values using the Assign node in a flow, or using a Form.


 - Step 3: Use RecordListToXml action

Drag-and-drop the RecordListToXml action to transform assigned variables to XML text.


 - Step 4: Fill RecordListToXml parameters

Fill RecordListToXml parameters to configure the XML export. Parameters are separated in 4 main parts: 

(Consult the demo component to obtain more details about parameters).


You must use ToObject() function to convert your Record List to a generic Object.


 - Step 5: Use output XML value

The output value is a text value that corresponds to an exported XML document.


2. RecordToXML

This method allows you to convert a single record into structured XML. You can add aliases to nodes through the AttributesConfig structure, as well as specifying a Namespace.


- Step 1: Create a Record type variable

Create a new variable of Record type, that should be transformed into XML text. Each Record attribute represents a XML attribute. Your variable MUST always be a Record type, not directly the type of a Record. 

Your record lists and structures must always be records. You cannot directly use the types you create when mapping structures and record lists, otherwise the extension will not be able to fill out your structures.


- Step 2: Fill the created Record List type variable 

Fill the variable with the corresponding values to put in each XML attribute. You can assign values using the Assign node in a flow, or using a Form.


- Step 3: Use RecordToXml action 

Drag-and-drop the RecordToXml action to transform your Record type variable into XML text.

- Step 4: Fill RecordToXml parameters

Fill RecordToXml parameters to configure the XML export. Parameters are separated in 3 main parts: 

(Consult the demo component to obtain more details about parameters). 


You must use ToObject() function to convert your Record to a generic Object.


- Step 5: Use output XML value

The output variable is a text value that contains the exported XML document.


3. XmlToRecordList

This method allows you to parse XML and fill out a RecordList. No outputs will be returned, as the RecordList you select will be filled with the result of the parse. You may choose to ignore the XML declaration and namespace, as well as define behaviour with regards to attribute prefixes and root nodes.


- Step 1: Create a Record list type variable

Create a new variable of Record List type that will be used as output, corresponding to the XML structure provided as input. Each Record attribute represents a XML attribute. Your variable MUST always be a Record List type, not directly the type of a Record. For more info, check the FAQ.


Your record lists and structures must always be records. You cannot directly use the types you create when mapping structures and record lists, otherwise the extension will not be able to fill out your structures. 


- Step 2: Configure the XML text variable

Create and configure a variable with the XML text to be transformed in a Record List. The provided XML, must match the structure given to the Record List variable created in the last step.


- Step 3: Use XmlToRecordList action 

Drag-and-drop the XmlToRecordList action to transform your XML text into a Record List. 


 - Step 4: Fill XmlToRecordList parameters

Fill the action parameters to configure the XML transformation into a Record List. Parameters are separated in 4 main parts:

(Consult the demo component to obtain more details about parameters).

You must use ToObject() function to convert your Record List to a generic Object.


- Step 5: Use output Record List value

The output Record List values, corresponding to the provided XML, has been put inside the Record List variable sent as the input parameter of the action.


Note: It is recommended to consult the demo for more details about the implementation, and examples of transformation between Records and RecordLists into XML and vice-versa.


FAQ

1. I can't use my structures as inputs in the exposed actions, as they need an Object type. How do I structure my inputs? 

Regardless of the content of your structures, the extension must receive your structures as generic Objects. You must always feed your structures and record lists using the ToObject() OutSystems method. 


2. Both RecordToXml and XmlToRecordList always return empty structures and empty record lists. How can I ensure the extension properly maps results to my structures? 

Your record lists and structures must always be records. You cannot directly use the types you create when mapping structures and record lists, otherwise the extension will not be able to fill out your structures.


3. I get an error regarding multiple root nodes when I use the RecordListToXml action. What do I need to do?

When you parse multiple records in a record list and attempt to convert it to XML, the resulting XML must always have a global root node in order to be valid (one single node from which all other nodes are descendants). You can use the AddRootNode flag to ensure this.


4. My XML has multiple namespaces and the fields aren't mapping correctly to my output structure. How do I ensure the extension matches values correctly?

You'll need to identify the full name of the attributes in the AttributesConfig structure like so:

For a code example, check this thread with a modified demo espace and multiple namespaces in the same XML. Please note that for very complex XML structures with multiple namespaces and attribute names, this can become very cumbersome to develop and maintain. Consider pre-processing your XML if possible.

Support Options
This component is not supported by OutSystems. You may use the discussion forums to leave suggestions or obtain best-effort support from the community, including from Afonso Carvalho who created this component.
Dependencies
XML Records has no dependencies.