-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsftToXML.pcode
132 lines (91 loc) · 3.17 KB
/
psftToXML.pcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
class psoftToXML
method RowsetToXML(&parentNode As XmlNode, &rowSetIn As Rowset) Returns XmlNode;
method RecordToXML(&parentNode As XmlNode, &recordIn As Record) Returns XmlNode;
method FieldToXML(&ParentNode As XmlNode, &fieldIn As Field) Returns XmlNode;
method RowToXML(&ParentNode As XmlNode, &rowIn As Row) Returns XmlNode;
method psoftToXML();
property array of string fieldsToSkip;
private
instance string &psObjectTypeString;
end-class;
method psoftToXML
&psObjectTypeString = "PSOBJECTTYPE";
%This.fieldsToSkip = CreateArrayRept("", 0);
end-method;
method FieldToXML
/+ &ParentNode as XmlNode, +/
/+ &fieldIn as Field +/
/+ Returns XmlNode +/
Local XmlNode &outNode;
Local XmlNode &fldNode, &tempNode;
&fldNode = &ParentNode.AddElement(&fieldIn.Name);
&fldNode.AddAttribute("PSFIELDTYPE", &fieldIn.Type);
&fldNode.AddAttribute(%This.psObjectTypeString, "FIELD");
If &fieldIn.IsEditXlat Then
&fldNode.AddAttribute("LongTranslateValue", &fieldIn.LongTranslateValue);
End-If;
Evaluate &fieldIn.Type
When = "LONGCHAR"
When = "IMAGE"
When = "IMAGEREFERENCE"
If All(&fieldIn.Value) Then
&tempNode = &fldNode.AddCDataSection(&fieldIn.Value);
End-If;
Break;
When = "NUMBER";
&tempNode = &fldNode.AddText(&fieldIn.Value);
Break;
When-Other
If All(&fieldIn.Value) Then
&tempNode = &fldNode.AddText(&fieldIn.Value);
End-If;
Break;
End-Evaluate;
Return &outNode;
end-method;
method RecordToXML
/+ &parentNode as XmlNode, +/
/+ &recordIn as Record +/
/+ Returns XmlNode +/
Local XmlNode &outNode, &fieldNode;
Local integer &i;
&outNode = &parentNode.AddElement(&recordIn.Name);
&outNode.AddAttribute(%This.psObjectTypeString, "RECORD");
For &i = 1 To &recordIn.FieldCount
If %This.fieldsToSkip.Find(&recordIn.GetField(&i).Name) <= 0 Then
&fieldNode = %This.FieldToXML(&outNode, &recordIn.GetField(&i));
End-If;
End-For;
Return &outNode;
end-method;
method RowToXML
/+ &ParentNode as XmlNode, +/
/+ &rowIn as Row +/
/+ Returns XmlNode +/
Local XmlNode &outNode, &recNode;
Local integer &i;
&outNode = &ParentNode.AddElement("ROW");
&outNode.AddAttribute(&psObjectTypeString, "ROW");
&outNode.AddAttribute("RowNumber", String(&rowIn.RowNumber));
For &i = 1 To &rowIn.RecordCount
&recNode = %This.RecordToXML(&outNode, &rowIn.GetRecord(&i));
End-For;
Local XmlNode &rsNode;
For &i = 1 To &rowIn.ChildCount
&rsNode = %This.RowsetToXML(&outNode, &rowIn.GetRowset(&i));
End-For;
Return &outNode;
end-method;
method RowsetToXML
/+ &parentNode as XmlNode, +/
/+ &rowSetIn as Rowset +/
/+ Returns XmlNode +/
Local XmlNode &outNode, &rowNode;
Local integer &i;
&outNode = &parentNode.AddElement(&rowSetIn.DBRecordName);
&outNode.AddAttribute(&psObjectTypeString, "ROWSET");
For &i = 1 To &rowSetIn.ActiveRowCount
&rowNode = %This.RowToXML(&outNode, &rowSetIn.GetRow(&i));
End-For;
Return &outNode;
end-method;