-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.p
More file actions
94 lines (72 loc) · 2.93 KB
/
Node.p
File metadata and controls
94 lines (72 loc) · 2.93 KB
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
############################################################
# $Id: Node.p,v 1.18 2011-10-05 00:51:18 misha Exp $
@CLASS
Als/Utils/Node
############################################################
@auto[]
$sDummyRoot[dummy-root-tag]
###
############################################################
# print $xNode as string
@toString[xNode;sRootTag][result;xDoc;_tmp]
^if($xNode){
$xDoc[^xdoc::create[$sDummyRoot]]
$_tmp[^xDoc.documentElement.appendChild[^xDoc.importNode[$xNode](1)]]
$result[^Als/Utils/Doc:toString[$xDoc]]
$result[^result.match[</?^taint[regex][$sDummyRoot]>][g]{}]
}{
$result[]
}
^if(def $sRootTag){
$result[^self.tag[$sRootTag;;$result]]
}
###
############################################################
# print $xNode VALUE as string: <aaa><bbb>ccc</bbb></aaa> => "<bbb>ccc</bbb>"
@valueToString[xNode;sRootTag][result]
$result[^self.toString[$xNode]]
^if(def $result){
$result[^result.match[^^<(^taint[regex][$xNode.nodeName])[^^>]*>(.*)</\1>^$][]{$match.2}]
}
^if(def $sRootTag){
$result[^self.tag[$sRootTag;;$result]]
}
###
############################################################
@tag[sTagName;oAttrs;sBody]
^if(def $sTagName){
$result[<$sTagName^if(def $oAttrs){^oAttrs.string[]}^if(def $sBody){>$sBody</$sTagName>}{/>}]
}{
$result[$sBody]
}
###
############################################################
# go through all nodes in $hNodeList and execute $jCode
@foreach[hNodeList;hNodeName;sNode;sAttr;jCode;sSeparator][result;i;xNode]
$result[^for[i](0;$hNodeList-1){$xNode[$hNodeList.$i]^if(^self._isRequestedNode[$xNode;$hNodeName]){$caller.$sNode[$xNode]^if(def $sAttr){$caller.$sAttr[^Als/Utils/Attrs:hash[$xNode]]}$jCode}}[$sSeparator]]
###
############################################################
# go through all children for $xParent and execute $jCode
@foreachChild[xParent;hNodeName;sNode;sAttr;jCode;sSeparator][result;xNode]
$xNode[$xParent.firstChild]
$result[^while($xNode){^if(^self._isRequestedNode[$xNode;$hNodeName]){$caller.$sNode[$xNode]^if(def $sAttr){$caller.$sAttr[^Als/Utils/Attrs:hash[$xNode]]}$jCode}$xNode[$xNode.nextSibling]}[$sSeparator]]
###
############################################################
# get children of $xParent as hash
@getChildren[xParent;hNodeName][result;xNode]
$result[^hash::create[]]
$xNode[$xParent.firstChild]
^while($xNode){^if(^self._isRequestedNode[$xNode;$hNodeName]){$result.[$xNode.nodeName][^self.toString[$xNode]]}$xNode[$xNode.nextSibling]}
###
############################################################
@getAttributes[uData][result]
$result[^Als/Utils/Attrs:hash[$uData]]
###
############################################################
@printAttributes[uData;uExclude;uAddon][result]
$result[^Als/Utils/Attrs:string[$uData;;$uExclude;$uAddon]]
###
############################################################
@_isRequestedNode[xNode;hNodeName][result]
$result($xNode.nodeType == $xdoc:ELEMENT_NODE && (!def $hNodeName || def $hNodeName.[$xNode.nodeName]))
###