%XML.Schema
class %XML.Schema extends %Library.RegisteredObject
The %XML.Schema controls creation of an XML Schema from Caché. It generates a complete XML document that contains the schema including the <?xml> tag. XML types are added to the schema by using the AddSchemaType() method. The schema is build up in an XML DOM by AddSchemaType() and may later be output using %XML.Writer. The DocumentNode() or Tree() methods of the %XML.Writer class can be used to output the schema.XML namespace handling is for the most part automatic. %XML.Schema adds namespaces for which %XML.Writer then automatically creates prefixes for the XML output as needed. The XML namespaces for which schemas are created are listed in the Namespaces property which is a list of strings. The GetSchema method is used to get the XML DOM node for a namespace's schema.
The following example can be executed in the SAMPLES namespace.
; Get %XML.Schema instance. set schema=##class(%XML.Schema).%New() set namespace="http://tempuri.org/ISC/Samples" set schema.DefaultNamespace=namespace ; Get %XML.Writer instance. set writer=##class(%XML.Writer).%New() set writer.Indent=1 do writer.AddSchemaNamespace() do writer.AddNamespace(namespace,"sample") ; Add Company. Note that referenced types are also added. set status=schema.AddSchemaType("Sample.Company") if $system.Status.IsError(status) do $system.Status.DisplayError(status) quit ; Add Vendor. set status=schema.AddSchemaType("Sample.Vendor") if $system.Status.IsError(status) do $system.Status.DisplayError(status) quit ; Verify that we have just our expected namespace. ; This is included for just for illustration. if (schema.Namespaces.Count()'=1) || (schema.Namespaces.GetAt(1)'=namespace) { write !,"Unexpected namespace found",! write !,"List Of Namespace: ",! for i=1:1:schema.Namespaces.Count() { write " ",schema.Namespaces.GetAt(i),! } write ! quit } ; Output the schema. set status=writer.DocumentNode(schema.GetSchema(namespace))
// className is the name of a class which references classes defined in // multiple namespaces. For example: className="test.A" in namespace "urn:testA", // test.A references test.B (in namespace "urn:testB") and test.C (in namespace "urn:testC"). try { #; get a schema writer set schemaWriter = ##class(%XML.Schema).%New() set sc = schemaWriter.AddSchemaType(className) if ($$$ISOK(sc)) { set namespaces = schemaWriter.Namespaces for i=1:1:namespaces.Count() { set ns=namespaces.GetAt(i) // set file path according to application dependent formula set locations(ns)="c:\temp\"_$piece(ns,":",2)_".xml" do schemaWriter.DefineLocation(ns,locations(ns)) } for i=1:1:namespaces.Count() { set ns=namespaces.GetAt(i) set schema = schemaWriter.GetSchema(ns) set writer = ##class(%XML.Writer).%New() do writer.OutputToFile(locations(ns)) set writer.Indent = 1 set sc=writer.DocumentNode(schema) If $$$ISERR(sc) do $system.OBJ.DisplayError(sc) Quit do writer.Reset() } } else { do $system.OBJ.DisplayError(sc) } } catch(tException) { do $system.OBJ.DisplayError(tException.AsStatus()) }
Property Inventory
Method Inventory
Properties
The normal format of an array name for a List is ArrayOf
The normal format of an array name for an Array is ArrayOf
Methods
The return value of this method is ignored.
top is the optional override of the type name.
format is the parameter formatting type ("literal", "encoded" or "encoded12") to be used for this object. In addition, the value "element" is the same as "literal" formatting with an element at the top level. The default value for format is "" which currently is the same as the "literal" formatting, but may be a unique Cache encoding in the future.
summary=true if summary type is to be created.
input=true means that the schema for the input XML will be generated,
otherwise the schema for the output XML will be generated. The default is
input=false. Normally, this argument is not relevant since the all properties
of a class participate in input and output.
refOnly=true means that only the portions of the schema for
referenced types are generated. The schema for this class is not generated.
Default is refOnly=false that generates the entire schema.
Inherited Members
Inherited Methods
- %AddToSaveSet()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Extends()
- %GetParameter()
- %IsA()
- %IsModified()
- %New()
- %NormalizeObject()
- %ObjectModified()
- %OriginalNamespace()
- %PackageName()
- %RemoveFromSaveSet()
- %SerializeObject()
- %SetModified()
- %ValidateObject()