InterSystems IRIS Data Platform 2019.2  /  Using XML Tools

Using XML Tools
Generating Classes from XML Schemas
Previous section           Next section
InterSystems: The power behind what matters   

Studio provides a wizard that reads an XML schema (from a file or URL) and generates a set of XML-enabled classes that correspond to the types defined in the schema. All the classes extend %XML.Adaptor. You specify a package to contain the classes, as well as various options that control the details of the class definitions.
The wizard is also available as a class method, which you can also use. Internally, the SOAP Wizard uses this method when it reads a WSDL document and generates web clients or web services; see Creating Web Services and Web Clients.
This chapter includes information on the following topics:
This wizard does not load data into InterSystems IRIS. If you need to load data after generating classes, see the chapter “Importing XML into Objects.”
The XML declaration of any XML document that you use should indicate the character encoding of that document, and the document should be encoded as declared. If the character encoding is not declared, InterSystems IRIS uses the defaults described in “Character Encoding of Input and Output,” earlier in this book. If these defaults are not correct, modify the XML declaration so that it specifies the character set actually used.
Using the Wizard
To use the XML Schema Wizard:
  1. Select Tools > Add-Ins > XML Schema Wizard.
  2. On the first screen, you specify the XML schema to use. Do one of the following:
  3. Select Next.
    The next screen displays the schema so that you can verify that you have chosen the correct one.
  4. Optionally select the following options:
  5. Select Next.
    The next screen displays some basic information on options about the classes to generate.
  6. On this screen, specify the following options:
  7. Select Next.
  8. On the next screen, specify the following options:
  9. Select Finish.
The wizard then generates the classes and, if requested, compiles them.
For properties of these classes, if the corresponding element in the schema has a name that starts with an underscore (_), the name of the property starts with a percent sign (%).
Generating the Classes Programmatically
The XML Schema Wizard is also available as the Process() method of the %XML.Utils.SchemaReader class. To use this method:
  1. Create an instance of %XML.Utils.SchemaReader.
  2. Optionally set properties of the instance to control its behavior. For details, see the class documentation for %XML.Utils.SchemaReader.
  3. Optionally create an InterSystems IRIS multidimensional array to contain information about additional settings. For details see the Process() method in the class documentation for %XML.Utils.SchemaReader.
  4. Invoke the Process() method of your instance:
    method Process(LocationURL As %String, 
                   Package As %String = "Test", 
                   ByRef Features As %String) as %Status
Default InterSystems IRIS Data Types for Each XSD Type
For each property that it generates, the XML Schema Wizard automatically uses an appropriate InterSystems IRIS data type class, depending on the XSD type specified in the schema. The following table lists the XSD types and the corresponding InterSystems IRIS data types:
InterSystems IRIS Data Types Used for XML Types
XSD Type in Source Document Data Type in the Generated InterSystems IRIS Classes
anyURI %xsd.anyURI
base64Binary %xsd.base64Binary or %Stream.GlobalBinary, depending on options you chose. It is your responsibility to determine if each string might exceed the string length limit, and if so, to modify the generated property from %xsd.base64Binary to an appropriate stream class.)
boolean %Boolean
byte %xsd.byte
date %Date
dateTime %TimeStamp
decimal %Numeric
double %xsd.double
float %xsd.float
hexBinary %xsd.hexBinary
integer %Integer
long %Integer
negativeInteger %xsd.negativeInteger
nonNegativeInteger %xsd.nonNegativeInteger
nonPositiveInteger %xsd.nonPositiveInteger
positiveInteger %xsd.positiveInteger
short %xsd.short
string %String (Note: It is your responsibility to determine if each string might exceed the string length limit, and if so, to modify the generated type to an appropriate stream class.)
time %Time
unsignedByte %xsd.unsignedByte
unsignedInt %xsd.unsignedInt
unsignedLong %xsd.unsignedLong
unsignedShort %xsd.unsignedShort
no type given %String
Property Keywords for the Generated Properties
For each property that it generates, the XML Schema Wizard also automatically sets the following keywords, using information in the schema:
Parameters for the Generated Properties
For each property that it generates, the XML Schema Wizard automatically sets XMLNAME, XMLPROJECTION, and all other XML-related parameters as needed. For information on these, see Projecting Objects to XML. It also sets other parameters such as MAXVAL, MINVAL, and VALUELIST as appropriate.
Adjusting the Generated Classes for the Extremely Long Strings
In rare cases, you might need to edit the generated classes to accommodate extremely long strings or binary values, beyond the string length limit.
For any string types, an XML schema does not contain any information to indicate how long the strings might be. The XML Schema Wizard maps any string values to the InterSystems IRIS %String class, and it maps any base64Binary values to the %xsd.base64Binary class. These choices might not be appropriate, depending on the data that the class is intended to carry.
Before using the generated classes, you should do the following:

Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-09-18 05:38:13