|
1 "{ Package: 'stx:goodies/xmlsuite/core' }" |
|
2 |
|
3 "{ NameSpace: XML }" |
|
4 |
|
5 Object subclass:#NodeTag |
|
6 instanceVariableNames:'namespace type qualifier' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'XML-VW-Parsing' |
|
10 ! |
|
11 |
|
12 NodeTag comment:'In XML all elements or nodes are delimited by start and end tags (or empty-element tags) and instances of this class are used to represent the name which appears in those tags. The name is composed of a simple type name |
|
13 |
|
14 Instance Variables: |
|
15 namespace <String> URI of the (XML) namespace of the element or attribute |
|
16 type <String> Name of tag, used to indicate element type, within the chosen namespace |
|
17 qualifier <String> type qualifier of the original XML document. Two NodeTags are considered equivalent if their namespace and type are equal, even if the qualifiers are different. This is primarily used only if it is desired to store the XML Document as a serialized string again. Qualiofiers are used with xmlns and xmlns:foo attributes to discover the namespace of the NodeTag. |
|
18 ' |
|
19 ! |
|
20 |
|
21 |
|
22 !NodeTag methodsFor:'accessing'! |
|
23 |
|
24 expandedName |
|
25 |
|
26 ^namespace isEmpty |
|
27 ifTrue: [type] |
|
28 ifFalse: [namespace, '#', type] |
|
29 ! |
|
30 |
|
31 namespace |
|
32 |
|
33 ^namespace |
|
34 ! |
|
35 |
|
36 qualifiedName |
|
37 |
|
38 ^self qualifier isEmpty |
|
39 ifTrue:[self type] |
|
40 ifFalse:[self qualifier , ':' , self type] |
|
41 |
|
42 "Created: / 23-04-2005 / 09:35:39 / janfrog" |
|
43 ! |
|
44 |
|
45 qualifier |
|
46 |
|
47 ^qualifier |
|
48 ! |
|
49 |
|
50 qualifier:aString |
|
51 |
|
52 qualifier := aString |
|
53 |
|
54 "Created: / 11-05-2005 / 19:52:02 / janfrog" |
|
55 ! |
|
56 |
|
57 type |
|
58 |
|
59 ^type |
|
60 ! ! |
|
61 |
|
62 !NodeTag methodsFor:'comparing'! |
|
63 |
|
64 < aNodeTag |
|
65 ^ self asString < aNodeTag asString |
|
66 ! |
|
67 |
|
68 = aNodeTag |
|
69 "Needed for canonical XML. REW" |
|
70 |
|
71 ^ (aNodeTag isKindOf:self class) |
|
72 and:[type = aNodeTag type and:[namespace = aNodeTag namespace]] |
|
73 ! |
|
74 |
|
75 hash |
|
76 "Needed for canonical XML. REW" |
|
77 ^type hash |
|
78 ! ! |
|
79 |
|
80 !NodeTag methodsFor:'converting'! |
|
81 |
|
82 asString |
|
83 |
|
84 ^qualifier isEmpty |
|
85 ifTrue: [type] |
|
86 ifFalse: [qualifier, ':', type] |
|
87 ! ! |
|
88 |
|
89 !NodeTag methodsFor:'initialization'! |
|
90 |
|
91 qualifier: q ns: ns type: typeStr |
|
92 namespace := ns. |
|
93 type := typeStr. |
|
94 qualifier := q. |
|
95 qualifier = 'xml' ifTrue: [ namespace := XMLNodeBuilder reservedXmlNamespace ]. |
|
96 ! ! |
|
97 |
|
98 !NodeTag methodsFor:'printing'! |
|
99 |
|
100 printOn: aStream |
|
101 |
|
102 aStream nextPutAll: '{', self asString, '}' |
|
103 ! ! |
|
104 |
|
105 !NodeTag methodsFor:'testing'! |
|
106 |
|
107 isLike: aName |
|
108 "strings do not come with namespace information, so when matching a string, we |
|
109 can only compare qualifier and type ... this is needed so elements in the dom tree |
|
110 can be accessed by name even when xmlns or xmlns:Q attributes are in use" |
|
111 |
|
112 ^aName isString |
|
113 ifTrue: [ self isLikeString: aName ] |
|
114 ifFalse: [ namespace = aName namespace and: [ type = aName type ] ] |
|
115 ! |
|
116 |
|
117 isLikeForValidation:aNodeTag |
|
118 "for validation purposes, nodetags are equal if qualifier and prefix are equal. |
|
119 this does not work if prefixes are re-defined, but it's better than the status quo" |
|
120 |
|
121 ^ qualifier = aNodeTag qualifier and:[type = aNodeTag type] |
|
122 ! |
|
123 |
|
124 isLikeString: aName |
|
125 | tmp | |
|
126 tmp := aName asCollectionOfSubstringsSeparatedBy: $:. |
|
127 tmp size > 2 |
|
128 ifTrue: |
|
129 [ XML::XMLSignal |
|
130 raiseErrorString: ('an element name is either NAME or Q:NAME: %1' |
|
131 bindWith: aName). ]. |
|
132 tmp size = 2 ifTrue:[ |
|
133 ^ qualifier = tmp first and:[type = (tmp at:2)] |
|
134 ]. |
|
135 ^ type = tmp first |
|
136 ! ! |
|
137 |
|
138 !NodeTag class methodsFor:'documentation'! |
|
139 |
|
140 version |
|
141 ^ '$Header: /cvs/stx/stx/goodies/xml/vw/NodeTag.st,v 1.12 2004/04/27 08:12:54 james Exp $' |
|
142 ! ! |