Using Caché XML Tools
Generating Classes from XML Schemas
[Back] [Next]
   
Server:docs2
Instance:LATEST
User:UnknownUser
 
-
Go to:
Search:    

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 in Caché.
This chapter includes information on the following topics:
This wizard does not load data into Caché. If you need to load data after generating classes, see the chapter Importing XML into Caché Objects.”
Note:
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, Caché 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. On the first screen, you specify the XML schema to use. Do one of the following:
  2. Select Next.
    The next screen displays the schema so that you can verify that you have chosen the correct one.
  3. Optionally select the following options:
  4. Select Next.
    The next screen displays some basic information on options about the classes to generate.
  5. On this screen, specify the following options:
  6. Select Next.
  7. On the next screen, specify the following options:
  8. 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 a Caché 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 Caché Data Types for Each XSD Type
For each property that it generates, the XML Schema Wizard automatically uses an appropriate Caché data type class, depending on the XSD type specified in the schema. The following table lists the XSD types and the corresponding Caché data types:
Caché Data Types Used for XML Types
XSD Type in Source Document Data Type in the Generated Caché Classes
anyURI %xsd.anyURI
base64Binary %xsd.base64Binary or %Stream.GlobalBinary, depending on options you chose. Note that if long string operations are not enabled in Caché, it is your responsibility to determine if each string might exceed the long string 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
int %xsd.int
integer %Integer
long %Integer
negativeInteger %xsd.negativeInteger
nonNegativeInteger %xsd.nonNegativeInteger
nonPositiveInteger %xsd.nonPositiveInteger
positiveInteger %xsd.positiveInteger
short %xsd.short
string %String (Note: If long string operations are not enabled in Caché, it is your responsibility to determine if each string might exceed the long string 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 Long Strings
In some cases, you might need to edit the generated classes to accommodate long strings or long binary values.
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 Caché %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.
If you have not enabled long string operations in Caché, you should do the following:
If you have enabled long string operations in Caché: