From d151680a1570a4d19c81ef071ea4b84896cd49ce Mon Sep 17 00:00:00 2001 From: CaS Date: Fri, 12 Apr 2002 11:10:37 +0000 Subject: [PATCH] Added -nextElement git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13465 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/Additions/GSXML.m | 31 +++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9b05998f..d500108b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-04-12 Richard Frith-Macdonald + + * Source/Additions/GSXML.m: New method ([-nextElement]) to traverse + tree skipping non-element nodes. + Thu Apr 11 15:34:33 2002 Nicola Pero * Source/GSAttributedString.m ([GSMutableAttributedString diff --git a/Source/Additions/GSXML.m b/Source/Additions/GSXML.m index d99a5f241..4a2945e01 100644 --- a/Source/Additions/GSXML.m +++ b/Source/Additions/GSXML.m @@ -749,7 +749,7 @@ static NSMapTable *nodeNames = 0; /** * Return the children of this node * - * - (GSXMLNode*) nextElement: (GSXMLNode*)node + * - (GSXMLNode*) elementRecursive: (GSXMLNode*)node * { * while (node != nil) * { @@ -759,7 +759,7 @@ static NSMapTable *nodeNames = 0; * } * if ([node children] != nil) * { - * node = [self nextElement: [node children]]; + * node = [self elementRecursive: [node children]]; * } * else * { @@ -853,7 +853,7 @@ static NSMapTable *nodeNames = 0; } /** - * initialisae node + * initialise node */ - (id) initWithNamespace: (GSXMLNamespace*) ns name: (NSString*) name { @@ -993,7 +993,10 @@ static NSMapTable *nodeNames = 0; } /** - * return the next node at this level. + * Return the next node at this level. This method can return any type + * of node, and it may be more convenient to use the -nextElement node + * if you are parsing a document where you wish to ignore non-element + * nodes such as whitespace text separating elements. */ - (GSXMLNode*) next { @@ -1007,6 +1010,26 @@ static NSMapTable *nodeNames = 0; } } +/** + * Returns the next element node, skipping past any oyther node types + * (such as text nodes). If there is no element node to be returned, + * this method returns nil. + */ +- (GSXMLNode*) nextElement +{ + xmlNodePtr ptr = ((xmlNodePtr)(lib))->next; + + while (ptr->next != NULL) + { + if (ptr->type == XML_ELEMENT_NODE) + { + return [GSXMLNode nodeFrom: ptr->next]; + } + ptr = ptr->next; + } + return nil; +} + /** * Return the namespace of the node. */