-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxml.st
91 lines (77 loc) · 2.83 KB
/
xml.st
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
Namespace current: Smalltalk [
Namespace current: ShampooXML [
Exception subclass: Malformed [
<category: 'Shampoo-XML'>
]
Object subclass: ShNode [
<category: 'Shampoo-XML'>
<comment: 'My instances represent an abstract XML nodes. I act as an
abstract layer between Shampoo and system-dependent XML implementation'>
| underlyingXML |
ShNode class >> tagname: aString [
<category: 'instance creation'>
^(self new)
underlyingXML: (XML.Element tag: aString);
yourself
]
ShNode class >> from: aString [
<category: 'instance creation'>
[| doc |
doc := XML.XMLParser processDocumentString: aString
beforeScanDo: [:p | p validate: false].
^(self new)
underlyingXML: doc root;
yourself
] on: XML.MalformedSignal
do: [:e | Malformed new signal]
]
underlyingXML: anObject [
<category: 'private'>
underlyingXML := anObject
]
underlyingXML [
<category: 'private'>
^underlyingXML
]
attrMap [
<category: 'bridge'>
^Dictionary from:
(underlyingXML attributes collect:
[:each | each key type -> each value])
]
addAttribute: anAttrName value: aValueString [
<category: 'bridge'>
| attr |
attr := XML.Attribute name: anAttrName value: aValueString.
underlyingXML addAttribute: attr
]
addNode: aNode [
<category: 'bridge'>
underlyingXML addNode: aNode underlyingXML
]
elementsNamed: aString [
<category: 'bridge'>
^(underlyingXML elementsNamed: aString) collect:
[:each | ShNode new underlyingXML: each]
]
text [
<category: 'bridge'>
^underlyingXML characterData
]
printOn: aStream [
<category: 'bridge'>
underlyingXML printOn: aStream
]
]
ShNode subclass: ShText [
<category: 'Shampoo-XML'>
<comment: 'My instances represent a text XML nodes. I act as an
abstract layer between Shampoo and system-dependent XML implementation'>
ShText class >> text: aString [
^(self new)
underlyingXML: (XML.Text text: aString);
yourself
]
]
]
]