This topic describes the EGL record or handler that corresponds to an Extensible Markup Language (XML) string. Other topics describe the serviceLib.convertFromXML and serviceLib.convertToXMLfunctions that are used by a Rich UI developer to convert XML data to or from a variable, as might be necessary to access a third-party REST service.
You can define an EGL Record or Handler type that is the basis of a record (or array of records) used to process an XML string. The type includes details that are found in an XML Schema, which is a language for validating an XML string.
When you use the function XMLLib.convertToXML, you write the content of the EGL record to an XML string. When you use the function XMLLib.convertFromXML, you write the XML string into the EGL record; and if the string does not fulfill a validation rule specified in the record, the EGL Runtime issues a RuntimeException.
In a Rich UI application, XML may be the format of a message sent to or received from a REST service, but is never the format used in relation to a web (SOAP) service. The EGL Rich UI Proxy expects the data submitted from the application to a web (SOAP) service to be in JavaScript™ Object Notation (JSON) format, and the Proxy returns web (SOAP) service data to the application in JSON format.
<Employee> <EmpNo>10</EmpNo> <Name>Smith</Name> </Employee>
Record Employee {XMLValue = XMLStructureKind.sequence} EmpNo INT; Name STRING; end
In most cases, the Record type includes a set of field names that each match (in character and case) the name of an element or attribute in the XML string. If the names do not match, you use EGL properties to specify the XML element or attribute name.
Keep in mind this twofold usage: in one case, for XML-string assignment, and in another case, for validation.
<Sample color="green"></Sample>
Record root Sample Sample? {@XMLElement {nillable = true}}; end Record Sample {@XMLValue = XMLStructureKind.simpleContent} color STRING {@XMLAttribute{}}; value STRING; end
<root><Sample color="green"></Sample></root>
<root><Sample xsi:nil="true></Sample></root>
<Employee> <EmpNo department="Sales">10</EmpNo> <Name>Smith</Name> </Employee>
Record Employee{XMLStructure = xmlStructureKind.sequence} EmpNo EmpNumber; LastName STRING; end Record EmpNumber {XMLStructure = xmlStructureKind.simpleContent} detypement STRING {@XMLAttribute{}}; value INT; end
Fields of type ANY are not supported.
One Record type can be referenced from another Record type at any level of nesting.
Record Employee EmpNo INT; Name STRING?; end
For details on the different ways the EGL Runtime treats a null when writing a record to an XML string, see the XMLElement or XMLRootElement annotation, nillable field.
You cannot override those annotations when you declare a record based on the Record type.
Rich UI supports reading and writing XML strings that contain namespaces. You can reference a namespace in the following annotations: RootElement, XMLElement, and XMLAttribute.
If the XML contains a default namespace, you must reference the namespace when defining the record fields for each XML element in that namespace. Note that an XML attribute is never in a default namespace; an attribute either has a namespace prefix or is not in a namespace.
To gain a full understanding of the alternatives available to you in EGL, review the topics for the XML-related annotations. Also note the EGL Runtime issues an XMLProcessingException in some cases, as stated in “eglx.xml package.”