XmlDoc Object Creation
Use the CreateXmlDoc function to create an XmlDoc object. You can create either an empty object, and populate it with data, or you can specify an XML string that is then transformed into an XmlDoc object that you can then manipulate with PeopleCode.
If you're creating an empty XmlDoc object, and you also want to specify a particular document type declaration (DTD) to be used to validate your XML, immediately after you use the CreateXmlDoc function, you should use the CreateDocumentType method to specify the DTD, followed by the CreateDocumentElement method to associate the DTD with the root entity.
Local XmlDoc &inXMLDoc; Local XmlNode &docTypeNode; Local XmlNode &rootNode; &inXMLDoc = CreateXmlDoc(""); &docTypeNode = &inXMLDoc.CreateDocumentType("Personal", "", "Personal.dtd"); &rootNode = &inXMLDoc.CreateDocumentElement("root", "", &docTypeNode);
The preceding PeopleCode program produces the following XML:
<?xml version="1.0"?> <!DOCTYPE Personal SYSTEM "Personal.dtd"> </root>
After you've created your XmlDoc object, use the GenXmlString method to create an XML string. You can then use an Internet Script (iScript) Response object method to send the string as an XML response.
In the root tag, the attribute xmlns stands for the XML namespace. This allows you to define namespaces for tag names so that collisions can be avoided and validation logic can be run.
If you do not give a prefix for an XML namespace, but instead define it with the tag (xmlns) followed by a colon (:) and then a unique namespace, for example,
For example, this sort of functionality allows you to have two nodes named "Transaction", but one can be referenced by a "psft" namespace and another not, allowing for two nodes with the same name to exist, but each containing different data.
<?xml version="1.0"?> <root xmlns:psft="http://www.example.com"> <psft:Transaction>Value</psft:Transaction> <Transaction>Another</Transaction> </root>
Incorrect results can be returned when you have a namespace as in the above example, which belongs to the namespace defined in http://www.people.com. When the system tries to find the path of "root/Transaction", it may return multiple nodes when in fact the end user might only want to return one.
To avoid this, do one of the following:
Do not use FindNode. Use GetElementByTagName instead. This does not use XPath to resolve entries in the DOM. Instead, it works at a node by node basis, for example, by getting the root node, then getting the transactions node. This code may be a bit more complex to write, but you loose the richness of XPath.
Give every xmlns attribute a prefix. The system will use XPath correctly and find the node.
Unstructured XML should be transformed to structured if you want to use the full rowset abilities. PeopleSoft recommends transforming the data into a rowset-based message.
If you do not want to transform the data, you need to break it up using the Transaction tag around the equivalent of each level zero rowset, as shown in the example.
<?xml version="1.0" ?> - <SAMPLE_MSG> - <Transaction> - <QE_SALES_ORDER class="R"> <QE_ACCT_ID>26</QE_ACCT_ID> <QE_ACCOUNT_NAME>APG-65</QE_ACCOUNT_NAME> <QE_ADDRESS>F18 HORNET WAY</QE_ADDRESS> <QE_PHONE>(206)544-1264</QE_PHONE> <QE_FROMROWSET /> <QE_TOROWSET /> <QE_SEND_SOA_BTN /> <QE_SEND_SOS_BTN /> <QE_TRAN_SOA_BTN /> <QE_SEND_SQ_BTN /> <QE_TRAN_SOS_BTN /> <QE_TRAN_APCODE_BTN /> <QE_TRAN_SPCODE_BTN /> <QE_PUBXMLDOC_BTN /> <QE_CLEAR_BTN /> <DESCRLONG /> </QE_SALES_ORDER> </Transaction> - <Transaction> - <QE_SALES_ORDER class="R"> <QE_ACCT_ID>27</QE_ACCT_ID> <QE_ACCOUNT_NAME>JASON ACCOUNT</QE_ACCOUNT_NAME> <QE_ADDRESS>THE ADDRESS</QE_ADDRESS> <QE_PHONE>(PHONE NUMBER</QE_PHONE> <QE_FROMROWSET /> <QE_TOROWSET /> <QE_SEND_SOA_BTN /> <QE_SEND_SOS_BTN /> <QE_TRAN_SOA_BTN /> <QE_SEND_SQ_BTN /> <QE_TRAN_SOS_BTN /> <QE_TRAN_APCODE_BTN /> <QE_TRAN_SPCODE_BTN /> <QE_PUBXMLDOC_BTN /> <QE_CLEAR_BTN /> <DESCRLONG /> </QE_SALES_ORDER> </Transaction> </SAMPLE_MSG>