Structs for XML Data
You can use the ProcScript instructions xmlToStruct and structToXml to convert complex data from and to XML.
XML can be much more complex than Uniface component data because it supports unlimited levels of nesting. It also has data types that are not recognized by Uniface, and doctype declarations and schemas which define the structure but are not actually required in the Struct itself.
For example, XML comments, DOCTYPE declaration, and namespace declarations are usually ignored when converting to Structs (although they can be included if required). If you are converting from a Struct to XML, and you need these XML constructs in the output, you need to explicitly define them.
A basic Struct that represents XML data has the following structure:
- Top-level Struct for the document; can optionally have attributes for an XML declaration.
- Named Struct node with element name
- Named Struct with attribute name; attribute Structs must precede any child elements
- Named Struct leaf with element name
- Named Struct with application name
Each XML Struct must have an
xmlClass
annotation. This determines what type of XML construct the Struct
represents.
String Returned for an XML Struct
For example, given the following XML code:
<div class="note">Text can be <b>bold</b> or <em>italic</em></div>
The Struct function $dbgstring returns a formatted string that represents the Struct:
[] [div] [$tags] [xmlClass] = element [class] = note [$tags] [xmlClass] = attribute [] = Text can be [b] = bold [$tags] [xmlClass] = element [] = or [em] = italic [$tags] [xmlClass] = element
- Top-level Struct.
- Struct node.
-
$tags
Struct containing annotations for the member. -
xmlClass
shows that the member represents an XML element. - Struct leaf, with its value being the only member.
-
xmlClass
shows that the member represents an XML attribute. - Scalar struct. For more information, see Struct Leaves.