forked from SVGKit/SVGKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOMHelperUtilities.m
More file actions
87 lines (71 loc) · 2.59 KB
/
Copy pathDOMHelperUtilities.m
File metadata and controls
87 lines (71 loc) · 2.59 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
#import "DOMHelperUtilities.h"
#import "Element.h"
#import "NodeList.h"
#import "NodeList+Mutable.h" // needed for access to underlying array, because SVG doesnt specify how lists are made mutable
@implementation DOMHelperUtilities
/*! This useful method provides both the DOM level 1 and the DOM level 2 implementations of searching the tree for a node - because THEY ARE DIFFERENT
yet very similar
*/
+(void) privateGetElementsByName:(NSString*) name inNamespace:(NSString*) namespaceURI childrenOfElement:(Node*) parent addToList:(NodeList*) accumulator
{
/** According to spec, this is only valid for ELEMENT nodes */
if( [parent isKindOfClass:[Element class]] )
{
if( namespaceURI != nil && ! [parent.namespaceURI isEqualToString:namespaceURI] )
{
// skip
}
else
{
Element* parentAsElement = (Element*) parent;
/** According to spec, "tag name" for an Element is the value of its .nodeName property; that means SOMETIMES its a qualified name! */
BOOL includeThisNode = FALSE;
if( [name isEqualToString:@"*"] )
includeThisNode = TRUE;
if( !includeThisNode )
{
if( namespaceURI == nil ) // No namespace? then do a qualified compare
{
includeThisNode = [parentAsElement.tagName isEqualToString:name];
}
else // namespace? then do an UNqualified compare
{
includeThisNode = [parentAsElement.localName isEqualToString:name];
}
}
if( includeThisNode )
{
[accumulator.internalArray addObject:parent];
}
}
}
for( Node* childNode in parent.childNodes )
{
[self privateGetElementsByName:name inNamespace:namespaceURI childrenOfElement:childNode addToList:accumulator];
}
}
+(Element*) privateGetElementById:(NSString*) idValue childrenOfElement:(Node*) parent
{
/** According to spec, this is only valid for ELEMENT nodes */
if( [parent isKindOfClass:[Element class]] )
{
Element* parentAsElement = (Element*) parent;
if( [[parentAsElement getAttribute:@"id"] isEqualToString:idValue])
return parentAsElement;
#if DEBUG_DOM_MATCH_ELEMENTS_IDS_AND_NAMES
else
{
SVGKitLogVerbose(@"parent <%@ id='%@'..> does not match id='%@'", parentAsElement.nodeName, [parentAsElement getAttribute:@"id"], idValue );
SVGKitLogVerbose(@"parent <%@ id='%@'..> has %li child nodes = %@", parentAsElement.nodeName, [parentAsElement getAttribute:@"id"], parent.childNodes.length, parent.childNodes );
}
#endif
}
for( Node* childNode in parent.childNodes )
{
Element* childResult = [self privateGetElementById:idValue childrenOfElement:childNode];
if( childResult != nil )
return childResult;
}
return nil;
}
@end