This topic describes the EGL record that corresponds to an Extensible Markup Language (XML) string. Other topics describe the functions—serviceLib.convertFromXML and serviceLib.convertToXML—that are used by a Rich UI developer to convert XML data to or from a variable, as may be necessary to access a third-party REST service.
You can define an EGL Record part that is the basis of a record (or array of records) used to process an XML string. The Record part 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.
<Employee>
<EmpNo>10</EmpNo>
<Name>Smith</Name>
</Employee>
Record Employee {XMLStructure = xmlStructureKind.sequence}
EmpNo INT;
Name STRING;
end
In most cases, the Record part 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 {@XMlStructure = 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}
department STRING {@XMLAttribute{}};
value INT;
end
Fields of type ANY are not supported.
One Record part can be referenced from another Record part 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 property @XMLElement (or @XMLRootElement), property field nillable.
Details on those properties are in “@RootElement” and “XMLStructure.”
You cannot override those properties when you declare a record based on the Record part.
Details on those properties are in @XMLElement , @XMLAttribute and @XMLArray.
Rich UI supports reading and writing XML strings that contain namespaces. You can reference a namespace in the property @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 properties. Also note the EGL Runtime issues an XMLProcessingException in some cases, as stated in “Exception record for XML.”