Die XML-Deklaration wird in der Nachrichtenbaumstruktur durch ein Syntaxelement mit dem Feldtyp 'XMLNSC.XMLDeclaration' dargestellt.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE s1 PUBLIC "http://www.ibm.com/example.dtd" "example.dtd">
<s1>........</s1>
Die XML-Deklaration hat drei optionale Attribute: 'Version', 'Standalone' und 'Encoding'. Der XMLNSC-Parser definiert keine bestimmten Feldtypen für diese Attribute. Stattdessen werden sie anhand ihres Namens und anhand ihrer Position als untergeordnetes Element eines XML-Deklarationselements identifiziert.
CREATE FIRSTCHILD OF OutputRoot.XMLNSC TYPE XMLNSC.XmlDeclaration NAME 'XmlDeclaration';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Version = '1.0';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Encoding = 'UTF-8';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)StandAlone = 'yes';
Die erste Zeile ist optional; wird sie weggelassen, wird das Element 'XMLNSC.XMLDeclaration' automatisch erstellt, wenn in der zweiten Zeile auf es verwiesen wird.//Rootknoten der XML-Domäne erstellen
MBElement xmlRoot =
root.createElementAsLastChild(MbXMLNSC.PARSER_NAME);
//Übergeordneten Knoten der XML-Deklaration erstellen
MbElement xmlDecl =
xmlRoot.createElementAsFirstChild(MbXMLNSC.XML_DECLARATION);
xmlDecl.setName("XmlDeclaration");
MbElement version = xmlDecl.CreateElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Version", "1.0");
MbElement encoding = xmlDecl.CreateElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Encoding", "utf-8");
MbElement standalone =
xmlDecl.CreateElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Standalone", "yes");