XML Parsing PeopleCode

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

*/

/* Description: Extracts XML from RMUSER.AUDITSEARCH, Results long field from


RMUSER.AUDITSEARCHRESULTS
*/
/* and parses it. Then loads data from XML and long field to custom RMS tables for reporting.
*/
/
********************************************************************************************************
****/
Local XmlDoc &searchxml;
Local XmlNode &CB_Target, &CB_IdValue, &CB_SearchTimeStamp, &CB_SrchString,
&CB_CriterionName, &CB_CriterionValue, &CB_Field, &CB_Value, &CB_Operator,
&CB_CompoundCriteria, &CB_Union;
Local array of XmlNode &field1List, &field2List, &field3List, &field4List, &field5List, &field6List;
Local Record &CB_RMS_SEARCH, &CB_RMS_SRCHCRIT, &CB_RMS_SRCHUSER;
Local number &i, &j, &k;
Local string &Time_Stamp, &Time_Stamp1;
Local datetime &Time_Stamp2, &Time_Stamp3;
Local integer &Time_Stamp_Year, &Time_Stamp_Month, &Time_Stamp_Day, &Time_Stamp_Hr,
&Time_Stamp_min, &Time_Stamp_Sec;
&searchxml = CreateXmlDoc(CB_RMS_SRCH_AET.CB_SRCHSTRING);
/* Read the XML file */
&field1List = &searchxml.GetElementsByTagName("SearchTarget");
If &field1List.Len = 0 Then;
CB_RMS_SRCH_AET.CB_TARGET = "";
Else
&CB_Target = &field1List.Shift();
CB_RMS_SRCH_AET.CB_TARGET = &CB_Target.NodeValue;
End-If;
&field1List = &searchxml.GetElementsByTagName("IdValue");
If &field1List.Len = 0 Then
CB_RMS_SRCH_AET.CB_OPRID = "";
Else
&CB_IdValue = &field1List.Shift();
CB_RMS_SRCH_AET.CB_OPRID = &CB_IdValue.NodeValue;
End-If;
&field1List = &searchxml.GetElementsByTagName("SearchTimeStamp");
If &field1List.Len = 0 Then
CB_RMS_SRCH_AET.CB_TIME_STAMP.SetDefault();
Else
&CB_SearchTimeStamp = &field1List.Shift();
&Time_Stamp = &CB_SearchTimeStamp.NodeValue;
&Time_Stamp_Year = Value(Substring(&Time_Stamp, 1, 4));
&Time_Stamp_Month = Value(Substring(&Time_Stamp, 6, 2));
&Time_Stamp_Day = Value(Substring(&Time_Stamp, 9, 2));
&Time_Stamp_Hr = Value(Substring(&Time_Stamp, 12, 2));
&Time_Stamp_min = Value(Substring(&Time_Stamp, 15, 2));
&Time_Stamp_Sec = Value(Substring(&Time_Stamp, 18, 2));

&Time_Stamp2 = DateTime6(&Time_Stamp_Year, &Time_Stamp_Month, &Time_Stamp_Day,


&Time_Stamp_Hr, &Time_Stamp_min, &Time_Stamp_Sec);
rem Warning ("Time Stamp:" | &Time_Stamp2);
CB_RMS_SRCH_AET.CB_TIME_STAMP = &Time_Stamp2;
End-If;
&field1List = &searchxml.GetElementsByTagName("SearchString");
If &field1List.Len = 0 Then
CB_RMS_SRCH_AET.CB_SEARCH_STRING = "";
Else
&CB_CriterionName = &field1List.Shift();
CB_RMS_SRCH_AET.CB_SEARCH_STRING = &CB_CriterionName.NodeValue;
End-If;
Local string &SearchString1;
&SearchString1 = CB_RMS_SRCH_AET.CB_SEARCH_STRING;
SQLExec("Insert into PS_CB_RMS_SEARCH values (:1,:2,:3,to_timestamp(:4,'yyyy-mm-dd
hh24.mi.ss.ff'),%textin(:5))", CB_RMS_SRCH_AET.CB_SEARCHID, CB_RMS_SRCH_AET.CB_TARGET,
CB_RMS_SRCH_AET.CB_OPRID, CB_RMS_SRCH_AET.CB_TIME_STAMP, &SearchString1);
&field1List = &searchxml.GetElementsByTagName("CriterionName");
&field2List = &searchxml.GetElementsByTagName("CriterionValue");
&k = &field1List.Len;
If &field1List.Len = 0 Then;
CB_RMS_SRCH_AET.CB_CRIT_NAME = "";
Else
For &i = 1 To &k;
&CB_CriterionName = &field1List.Shift();
CB_RMS_SRCH_AET.CB_CRIT_NAME = &CB_CriterionName.NodeValue;
If &field2List.Len = 0 Then
CB_RMS_SRCH_AET.CB_VALUE = ""
Else
&CB_CriterionValue = &field2List.Shift();
CB_RMS_SRCH_AET.CB_VALUE = &CB_CriterionValue.NodeValue;
End-If;
SQLExec("insert into PS_CB_RMS_SRCHCRIT values(:1,:2,:3,to_timestamp(:4,'yyyy-mm-dd
hh24.mi.ss.ff'),:5,:6)", CB_RMS_SRCH_AET.CB_SEARCHID, CB_RMS_SRCH_AET.CB_TARGET,
CB_RMS_SRCH_AET.CB_OPRID, CB_RMS_SRCH_AET.CB_TIME_STAMP,
CB_RMS_SRCH_AET.CB_CRIT_NAME, CB_RMS_SRCH_AET.CB_VALUE);
End-For;
End-If;
&field1List
&field3List
&field4List
&field5List
&field6List

=
=
=
=
=

&searchxml.GetElementsByTagName("Field");
&searchxml.GetElementsByTagName("Value");
&searchxml.GetElementsByTagName("Operator");
&searchxml.GetElementsByTagName("CompoundCriteria");
&searchxml.GetElementsByTagName("Union");

&j = &field1List.Len;
If &field1List.Len = 0 Then
CB_RMS_SRCH_AET.CB_FIELD = "";
Else

For &i = 1 To &j;


&CB_Field = &field1List.Shift();
CB_RMS_SRCH_AET.CB_FIELD = &CB_Field.NodeValue;
If &field3List.Len = 0 Then
CB_RMS_SRCH_AET.CB_VALUE = ""
Else
&CB_Value = &field3List.Shift();
CB_RMS_SRCH_AET.CB_VALUE = &CB_Value.NodeValue;
End-If;
If &field4List.Len = 0 Then
CB_RMS_SRCH_AET.CB_OPERATOR = ""
Else
&CB_Operator = &field4List.Shift();
CB_RMS_SRCH_AET.CB_OPERATOR = &CB_Operator.NodeValue;
End-If;
If &field5List.Len = 0 Then
CB_RMS_SRCH_AET.CB_COMPOUND_CRIT = ""
Else
&CB_CompoundCriteria = &field5List.Shift();
CB_RMS_SRCH_AET.CB_COMPOUND_CRIT = &CB_CompoundCriteria.NodeValue;
End-If;
If &field6List.Len = 0 Then
CB_RMS_SRCH_AET.CB_UNION = ""
Else
&CB_Union = &field6List.Shift();
CB_RMS_SRCH_AET.CB_UNION = &CB_Union.NodeValue;
End-If;
SQLExec("select 'Y' from PS_CB_RMS_SRCHUSER where CB_SEARCHID = :1 and CB_FIELD = :2 and
CB_VALUE = :3", CB_RMS_SRCH_AET.CB_SEARCHID, CB_RMS_SRCH_AET.CB_FIELD,
CB_RMS_SRCH_AET.CB_VALUE, &exists);
If &exists Not = "Y" Then
SQLExec("Insert into PS_CB_RMS_SRCHUSER values (:1,:2,:3,to_timestamp(:4,'yyyy-mm-dd
hh24.mi.ss.ff'),:5,:6,:7,:8,:9)", CB_RMS_SRCH_AET.CB_SEARCHID, CB_RMS_SRCH_AET.CB_TARGET,
CB_RMS_SRCH_AET.CB_OPRID, CB_RMS_SRCH_AET.CB_TIME_STAMP, CB_RMS_SRCH_AET.CB_FIELD,
CB_RMS_SRCH_AET.CB_VALUE, CB_RMS_SRCH_AET.CB_OPERATOR,
CB_RMS_SRCH_AET.CB_COMPOUND_CRIT, CB_RMS_SRCH_AET.CB_UNION);
End-If;
Warning ("Search Id " | CB_RMS_SRCH_AET.CB_SEARCHID);
End-For;
End-If;

You might also like