10
10
modify it under the terms of the GNU Lesser General Public
11
11
License as published by the Free Software Foundation; either
12
12
version 3 of the License, or (at your option) any later version.
14
14
This library is distributed in the hope that it will be useful,
15
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
179
185
- (NSXMLNode*) childAtIndex: (NSUInteger)index
181
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
187
return [internal->children objectAtIndex: index];
184
190
- (NSUInteger) childCount
186
[self notImplemented: _cmd]; // FIXME ... fetch from libxml
192
return internal->childCount;
195
- (NSArray*) children
192
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
197
return internal->children;
195
200
- (id) copyWithZone: (NSZone*)zone
197
[self notImplemented: _cmd];
202
id c = [[self class] allocWithZone: zone];
204
c = [c initWithKind: internal->kind options: internal->options];
205
[c setName: [self name]];
206
[c setURI: [self URI]];
207
[c setObjectValue: [self objectValue]];
208
[c setStringValue: [self stringValue]];
204
[_objectValue release];
215
if (GS_EXISTS_INTERNAL)
218
[internal->name release];
219
[internal->URI release];
220
[internal->children release];
221
[internal->objectValue release];
222
[internal->stringValue release];
223
GS_DESTROY_INTERNAL(NSXMLNode);
212
[self notImplemented: _cmd]; // FIXME ... remove from libxml
230
[(NSXMLElement*)internal->parent removeChildAtIndex: [self index]];
235
return [internal->name hash];
216
238
- (NSUInteger) index
240
if (nil == internal->parent)
244
return [GSIVar(internal->parent, children) indexOfObjectIdenticalTo: self];
249
return [self initWithKind: NSXMLInvalidKind];
221
252
- (id) initWithKind:(NSXMLNodeKind) kind
227
- (id) initWithKind: (NSXMLNodeKind)kind options: (NSUInteger)options
258
- (id) initWithKind: (NSXMLNodeKind)kind options: (NSUInteger)theOptions
229
if ((self = [super init]) != nil)
231
[self notImplemented: _cmd]; // FIXME ... use libxml
260
Class theSubclass = [NSXMLNode class];
262
GSOnceMLog(@"WARNING the XML DOM classes are not currently implemented to a usable level, but we expect to have an implementation based on libxml2 in place for the next release.");
263
if (nil == (self = [super init]))
269
* We find the correct subclass for specific node kinds:
273
case NSXMLDocumentKind:
274
theSubclass = [NSXMLDocument class];
277
case NSXMLElementKind:
278
theSubclass = [NSXMLElement class];
282
theSubclass = [NSXMLDTD class];
285
case NSXMLEntityDeclarationKind:
286
case NSXMLElementDeclarationKind:
287
case NSXMLNotationDeclarationKind:
288
theSubclass = [NSXMLDTDNode class];
296
* Check whether we are already initializing an instance of the given
297
* subclass. If we are not, release ourselves and allocate a subclass instance
300
if (NO == [self isKindOfClass: theSubclass])
303
return [[theSubclass alloc] initWithKind: kind
304
options: theOptions];
307
/* Create holder for internal instance variables if needed.
309
GS_CREATE_INTERNAL(NSXMLNode)
311
/* If we are initializing for the correct class, we can actually perform
314
internal->kind = kind;
315
internal->options = theOptions;
316
internal->stringValue = @"";
320
- (BOOL) isEqual: (id)other
325
if (other == (id)self)
330
if (NO == [other isKindOfClass: [self class]])
335
if ([(NSXMLNode*)other kind] != internal->kind)
341
if (s != internal->name && NO == [s isEqual: internal->name])
347
if (s != internal->URI && NO == [s isEqual: internal->URI])
352
c = [other children];
353
if (c != internal->children && NO == [c isEqual: internal->children])
236
361
- (NSXMLNodeKind) kind
363
return internal->kind;
241
366
- (NSUInteger) level
243
368
NSUInteger level = 0;
244
NSXMLNode *tmp = _parent;
369
NSXMLNode *tmp = internal->parent;
246
371
while (tmp != nil)
374
tmp = GSIVar(tmp, parent);
259
384
- (NSString*) name
261
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
386
return internal->name;
389
- (NSXMLNode*) _nodeFollowingInNaturalDirection: (BOOL)forward
391
NSXMLNode *ancestor = internal->parent;
392
NSXMLNode *candidate = nil;
394
/* Node walking is a depth-first thingy. Hence, we consider children first: */
395
if (0 != internal->childCount)
397
NSUInteger theIndex = 0;
400
theIndex = (internal->childCount) - 1;
402
candidate = [internal->children objectAtIndex: theIndex];
405
/* If there are no children, we move on to siblings: */
406
if (nil == candidate)
410
candidate = internal->nextSibling;
414
candidate = internal->previousSibling;
418
/* If there are no siblings left for the receiver, we recurse down to the root
419
* of the tree until we find an ancestor with further siblings: */
420
while ((nil == candidate) && (nil != ancestor))
424
candidate = [ancestor nextSibling];
428
candidate = [ancestor previousSibling];
430
ancestor = GSIVar(ancestor, parent);
433
/* No children, no next siblings, no next siblings for any ancestor: We are
435
if (nil == candidate)
440
/* Sanity check: Namespace and attribute nodes are skipped: */
441
if ((NSXMLAttributeKind == GSIVar(candidate, kind))
442
|| (NSXMLNamespaceKind == GSIVar(candidate, kind)))
444
return [candidate _nodeFollowingInNaturalDirection: forward];
264
449
- (NSXMLNode*) nextNode
266
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
451
return [self _nodeFollowingInNaturalDirection: YES];
269
454
- (NSXMLNode*) nextSibling
271
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
456
return internal->nextSibling;
274
459
- (id) objectValue
461
return internal->objectValue;
279
464
- (NSXMLNode*) parent
466
return internal->parent;
284
469
- (NSString*) prefix
289
474
- (NSXMLNode*) previousNode
291
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
476
return [self _nodeFollowingInNaturalDirection: NO];
294
479
- (NSXMLNode*) previousSibling
296
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
481
return internal->previousSibling;
299
485
- (NSXMLDocument*) rootDocument
301
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
487
NSXMLNode *ancestor = internal->parent;
489
* Short-circuit evaluation gurantees that the nil-pointer is not
492
while ((ancestor != nil)
493
&& (NSXMLDocumentKind != GSIVar(ancestor, kind)))
495
ancestor = GSIVar(ancestor, parent);
497
return (NSXMLDocument*)ancestor;
304
500
- (NSString*) stringValue
502
return internal->stringValue;
310
505
- (NSString*) URI
312
return [self notImplemented: _cmd]; // FIXME ... fetch from libxml
507
return internal->URI; // FIXME ... fetch from libxml
315
510
- (NSString*) XMLString
320
515
- (NSString*) XMLStringWithOptions: (NSUInteger)options
322
return [self notImplemented: _cmd]; // FIXME ... generate from libxml
517
NSMutableString *returnValue = [NSMutableString string];
518
NSXMLNodeKind kind = [self kind];
520
if (kind == NSXMLAttributeKind)
522
[returnValue appendString: [self name]];
523
[returnValue appendString: @"=\""];
524
[returnValue appendString: [self stringValue]];
525
[returnValue appendString: @"\""];
529
// for all other types, do nothing for now...
325
535
- (void) setObjectValue: (id)value
327
ASSIGN(_objectValue, value);
537
ASSIGN(internal->objectValue, value);
330
- (void) setName: (NSString*)name
540
- (void) setName: (NSString *)name
332
[self notImplemented: _cmd]; // FIXME ... set in libxml
542
if (NSXMLInvalidKind != internal->kind)
544
ASSIGNCOPY(internal->name, name);
335
548
- (void) setStringValue: (NSString*)string
340
553
- (void) setURI: (NSString*)URI
342
[self notImplemented: _cmd]; // FIXME ... set in libxml
555
if (NSXMLInvalidKind != internal->kind)
557
ASSIGNCOPY(internal->URI, URI);
345
561
- (void) setStringValue: (NSString*)string resolvingEntities: (BOOL)resolve
347
[self notImplemented: _cmd]; // FIXME ... set in libxml
565
ASSIGNCOPY(internal->stringValue, string);
569
// need to actually resolve entities...
570
ASSIGNCOPY(internal->stringValue, string);
572
if (nil == internal->stringValue)
574
internal->stringValue = @""; // string value may not be nil
350
578
- (NSString*) XPath