How to Generate xml file using Peoplecode
You can create xml file by peoplecode
How to Generate xml file using Peoplecode
1. Create xml file by peoplecode then print data in message and copay data and save as xml file
import PSXP_XMLGEN:*;
/* You can also use XMLDoc class to create xml files from peoplecode. Here is a simple example. This creates an xml file with the contents of a table.
*/
Local XmlDoc &inXMLDoc;
Local XmlNode &rootNode, &childNode1, &childNode2, &textNode2;
Local string &xmlStr;
Local File &xmlFile;
Local number &i;
&file_name = “/Your Path/appserv/UAT/TESTXML.xml”;
&xmlFile = GetFile(&file_name, “W”, %FilePath_Absolute); /* Code to initialize the file object */
&inXMLDoc = CreateXmlDoc(“”);
&rootNode = &inXMLDoc.CreateDocumentElement(“root”);
Local Record &rec = CreateRecord(Record.TEST);
Local SQL &sql = CreateSQL(“SELECT * FROM PS_TEST “);
While &sql.Fetch(&rec)
&childNode1 = &rootNode.AddElement(Lower(&rec.Name));
For &i = 1 To &rec.FieldCount
&childNode2 = &childNode1.AddElement(Lower(&rec.GetField(&i).Name));
&textNode2 = &childNode2.AddText(&rec.GetField(&i).Value);
End-For;
End-While;
&xmlStr = &inXMLDoc.GenFormattedXmlString();
&xmlFile.WriteLine(&xmlStr);
&xmlFile.Close();
WinMessage(&xmlStr, 0);
2. Create xml file by peoplecode then write file xml to app server
You can use field change event or other event.
import PSXP_XMLGEN:*;
/* You can also use XMLDoc class to create xml files from peoplecode. Here is a simple example. This creates an xml file with the contents of a table. */
Local XmlDoc &inXMLDoc;
Local XmlNode &rootNode, &childNode1, &childNode2, &textNode2;
Local string &xmlStr;
Local File &xmlFile;
Local number &i;
&inXMLDoc = CreateXmlDoc(“”);
&rootNode = &inXMLDoc.CreateDocumentElement(“root”);
Local Record &rec = CreateRecord(Record.TEST);
Local SQL &sql = CreateSQL(“SELECT * FROM PS_TEST “);
While &sql.Fetch(&rec)
&childNode1 = &rootNode.AddElement(Lower(&rec.Name));
For &i = 1 To &rec.FieldCount
&childNode2 = &childNode1.AddElement(Lower(&rec.GetField(&i).Name));
&textNode2 = &childNode2.AddText(&rec.GetField(&i).Value);
End-For;
End-While;
&xmlStr = &inXMLDoc.GenFormattedXmlString();
WinMessage(&xmlStr, 0);