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:

Simple XML Structure

Simple XML Structure

  1.  Top-level Struct for the document; can optionally have attributes for an XML declaration.
  2.  Named Struct node with element name
  3.  Named Struct with attribute name; attribute Structs must precede any child elements
  4.  Named Struct leaf with element name
  5.  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:

[]  1
  [div]  2
    [$tags]  3
	  [xmlClass] = element  4
	[class] = note 5
	  [$tags]
	    [xmlClass] = attribute  6
	[] = Text can be  7
	[b] = bold  5
	  [$tags]
	    [xmlClass] = element 4
	[] = or  7
	[em] = italic  5
	  [$tags]
	    [xmlClass] = element
  1.  Top-level Struct.
  2.  Struct node.
  3.  $tags Struct containing annotations for the member.
  4.  xmlClass shows that the member represents an XML element.
  5.  Struct leaf, with its value being the only member.
  6.  xmlClass shows that the member represents an XML attribute.
  7.  Scalar struct. For more information, see Struct Leaves.

Related Topics