Suppressing the Namespace Prefix for the Type QName
Suppressing the Namespace Prefix for the Type QName
As described in Using XML Tools, when you generate output with %XML.WriterOpens in a new tab, you can include the XML type attribute; to do so, you specify the writer’s OutputTypeAttribute property as 1.
By default, the type attribute is written as a QName (qualified name), which indicates both the name of the type as well as the namespace to which the type belongs. For example:
<TeamA xmlns:s01="http://mynamespace" xsi:type="s01:TeamA">
You can define the corresponding InterSystems IRIS class definition so that the namespace prefix is suppressed. For example:
<TeamB xsi:type="TeamB">
For example, consider the following class definition:
Class STP.TeamA Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter NAMESPACE = "http://mynamespace";
Property Member1 as %String;
Property Member2 as %String;
}
The class STP.TeamB, which is not shown, has the same definition but also specifies SUPPRESSTYPEPREFIX as 1.
Both classes are used as properties in a third class:
Class STP.Container Extends (%RegisteredObject, %XML.Adaptor)
{
Parameter NAMESPACE = "http://mynamespace";
Property TeamA As STP.TeamA;
Property TeamB As STP.TeamB;
}
When we generate output for an instance of STP.Container (and we enable output of the XML type attribute), we see something like this:
<?xml version="1.0" encoding="UTF-8"?>
<Container xmlns="http://mynamespace"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<TeamA xmlns:s01="http://mynamespace" xsi:type="s01:TeamA">
<Member1 xsi:type="s:string">Jack O'Neill</Member1>
<Member2 xsi:type="s:string">Samantha Carter</Member2>
</TeamA>
<TeamB xsi:type="TeamB">
<Member1 xsi:type="s:string">Jasper O'Nelson</Member1>
<Member2 xsi:type="s:string">Sandra Chartres</Member2>
</TeamB>
</Container>
Notice that the <TeamA> element includes the xsi:type attribute, which equals "s01:TeamA". The namespace declaration in this element indicates that the s01 prefix refers to the namespace http://mynamespace.
The <TeamB> element, however, does not include a prefix within the xsi:type attribute.
The SUPPRESSTYPEPREFIX does not affect the namespace to which the XML type belongs. It just suppresses the writing of the type prefix.