Working with XML in Gosu

XML files describe complex structured data in a text-based format with strict syntax for data interchange. Gosu can read or write any XML document. If you have an associated XML Schema Definition (XSD) to define the document structure, Gosu parses the XML, which it validates using the schema, to produce a statically typed tree of XML elements with structured data. You can manipulate XML or generate XML without an XSD file, but Guidewire recommends that you use XSDs whenever possible in order to take advantage of programming shortcuts such as Gosu properties on each element and intelligent static typing.

Manipulating XML

To manipulate XML in Gosu, Gosu creates an in-memory representation of a graph of XML elements. The main Gosu class to handle an XML element is the class called XmlElement. Instead of manipulating XML by modifying text data in an XML file, your Gosu code can manipulate XmlElement objects. You can read in XML data from a file or other sources and parse it into a graph of XML elements. You can export a graph of XML elements as standard XML. For example, you can export an array of bytes containing XML data.

Gosu can manipulate structured XML documents in two ways:
Untyped nodes
Any XML can be created, manipulated, or searched as a tree of untyped nodes. This approach is similar to manipulating Document Object Model (DOM) untyped nodes. Gosu treats attribute and node values as strings.
Strongly typed nodes using an XSD
If the XML has an XSD file, you can create, manipulate, or search data with statically typed nodes that correspond to legal attributes and child elements. If you can provide an XSD file, the XSD approach is much safer. It dramatically reduces errors due to incorrect types or incorrect structure.

See also