Contents

XML Encoding Examples

In this section, we will look at how to create XML with PeopleCode. We do not use the message class to generate any XML. The PeopleCode is used to entirely generate the content.

Simple XML Output

This example shows how to produce a simple XML output in an handler. Below is the XML produced with the handler PeopleCode that is below. This is meant to demonstrate a few key concepts.

  • Producing an nested XML structure
  • Adding XML attributes to node
  • Show the different with character escaping differences between CDATA and Nodes
<?xml version="1.0"?>
<RESPONSE>
  <hello DEBUG_NODE="True">world</hello>
  <STRING_TEST_CDATA>
    <![CDATA[<p><b>I have characters that should be escaped</b></p>]]>
  </STRING_TEST_CDATA>
  <STRING_TEST>&lt;p&gt;&lt;b&gt;I have characters that should be escaped&lt;/b&gt;&lt;/p&gt;</STRING_TEST>
  <META isMETA="True">
    <OPRID>PS</OPRID>
    <CURRENT_TIME>2019-10-21-19.20.31.000000</CURRENT_TIME>
    <TRANSACTION_ID>d95ffa9d-f437-11e9-8a51-fef2b534ad6a</TRANSACTION_ID>
    <DBNAME>CS92U009</DBNAME>
  </META>
</RESPONSE>

The full handler PeopleCode to produce this XML is the following.

import PS_PT:Integration:IRequestHandler;

class xmlOutputExample1 implements PS_PT:Integration:IRequestHandler
   method onRequest(&msRequest As Message) Returns Message;
end-class;

method onRequest
   /+ &msRequest as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/


   Local Message &response;
   &response = CreateMessage(@("Operation." | &msRequest.OperationName), %IntBroker_Response);


   /* Setup response xml body */

   Local XmlDoc &xmlDocResponse;
   &xmlDocResponse = CreateXmlDoc("");

   Local XmlNode &responseRootNode;
   &responseRootNode = &xmlDocResponse.CreateDocumentElement("RESPONSE");


   Local XmlNode &xnTemp;
   Local XmlNode &xnChildNode;
   &xnChildNode = &xmlDocResponse.DocumentElement.AddElement("hello");
   &xnTemp = &xnChildNode.AddText("world");
   &xnChildNode.AddAttribute("DEBUG_NODE", "True");

   &xnChildNode = &xmlDocResponse.DocumentElement.AddElement("STRING_TEST_CDATA");

   Local string &s = "<p><b>I have characters that should be escaped</b></p>";
   &xnTemp = &xnChildNode.AddCDataSection(&s);

   &xnChildNode = &xmlDocResponse.DocumentElement.AddElement("STRING_TEST");
   &xnTemp = &xnChildNode.AddText(&s);

   Local XmlNode &nxMetaNode;
   &nxMetaNode = &xmlDocResponse.DocumentElement.AddElement("META");
   &nxMetaNode.AddAttribute("isMETA", "True");

   &xnTemp = &nxMetaNode.AddElement("OPRID").AddText(%OperatorId);
   &xnTemp = &nxMetaNode.AddElement("CURRENT_TIME").AddText(String(%Datetime));
   &xnTemp = &nxMetaNode.AddElement("TRANSACTION_ID").AddText(&msRequest.TransactionId);
   &xnTemp = &nxMetaNode.AddElement("DBNAME").AddText(%DbName);

   /* Push the generated XML to the response document */
   &response.SetXmlDoc(&xmlDocResponse);
   Return &response;

end-method;

Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with over two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

Work with Chris
PeopleSoft REST APIs in Minutes, Not Months
PeopleSoft Simple Web Services (SWS)

SWS turns SQL into production REST APIs — ready for AI, modern apps, and partner integrations. One install, unlimited potential.

  • Configuration-driven, no coding required
  • JSON, XML, and CSV output
  • Works across all PeopleSoft pillars
  • Built on 25+ years of PeopleSoft expertise
Looking for pain-free PeopleSoft web services?
PeopleSoft Simple Web Services (SWS)

A powerful PeopleSoft bolt-on that makes REST web services easy. You bring the SQL, SWS handles the rest.

  • Go from idea to production in minutes
  • Zero code migrations after install
  • JSON, XML, and CSV output supported
  • No PeopleCode or Integration Broker expertise required
Stop Building PeopleSoft Web Services the Hard Way
PeopleSoft Simple Web Services (SWS)

Traditional PeopleSoft web services cost $3,600–$13,000 each to develop. SWS deploys production REST APIs in under 5 minutes through configuration alone.

  • No PeopleCode or Integration Broker expertise required
  • Works across Campus Solutions, HCM, and Financials
  • Built-in pagination, caching, and nested data structures
  • Trusted by institutions across higher education and government
PeopleSoft REST APIs for AI, Modern Apps, and Integrations
PeopleSoft Simple Web Services (SWS)

Turn PeopleSoft data into clean REST APIs for AI integrations, modern applications, and vendor data feeds. Configuration-driven — no PeopleCode required.

  • Deploy production APIs in under 5 minutes
  • AI and LLM ready (RAG, chatbots, intelligent search)
  • JSON, XML, and CSV output
  • Zero modifications to delivered PeopleSoft objects