Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding ability to detach a child node without bothering to fix the na…

…mespaces.
  • Loading branch information...
commit 1a8ae62038d147c26d23d42b5a1f4f687bc1ba7a 1 parent 0044ccd
Robbie Hanson authored
Showing with 12 additions and 7 deletions.
  1. +10 −7 KissXML/DDXMLNode.m
  2. +2 −0  KissXML/Private/DDXMLPrivate.h
17 KissXML/DDXMLNode.m
View
@@ -1739,7 +1739,7 @@ + (void)removeAllNamespacesFromNode:(xmlNodePtr)node
* The attribute's surrounding prev/next pointers are properly updated to remove the attribute from the attr list.
* Then, if the clean flag is YES, the attribute's parent, prev, next and doc pointers are set to null.
**/
-+ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)flag
++ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)clean
{
xmlNodePtr parent = attr->parent;
@@ -1769,7 +1769,7 @@ + (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)flag
}
}
- if (flag)
+ if (clean)
{
// Nullify pointers
attr->parent = NULL;
@@ -1834,7 +1834,7 @@ + (void)removeAllAttributesFromNode:(xmlNodePtr)node
* The child's surrounding prev/next pointers are properly updated to remove the child from the node's children list.
* Then, if the clean flag is YES, the child's parent, prev, next and doc pointers are set to null.
**/
-+ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag
++ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)clean andFixNamespaces:(BOOL)fixNamespaces
{
xmlNodePtr parent = child->parent;
@@ -1866,11 +1866,14 @@ + (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag
}
}
- if (flag)
+ if (fixNamespaces)
{
// Fix namesapces (namespace references that now point outside tree)
+ // Note: This must be done before we nullify pointers so we can search up the tree.
[self recursiveFixDefaultNamespacesInNode:child withNewRoot:child];
-
+ }
+ if (clean)
+ {
// Nullify pointers
child->parent = NULL;
child->prev = NULL;
@@ -1886,7 +1889,7 @@ + (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag
**/
+ (void)detachChild:(xmlNodePtr)child
{
- [self detachChild:child andClean:YES];
+ [self detachChild:child andClean:YES andFixNamespaces:YES];
}
/**
@@ -1905,7 +1908,7 @@ + (void)removeChild:(xmlNodePtr)child
// We perform a bit of optimization here.
// No need to bother nullifying pointers since we're about to free the node anyway.
- [self detachChild:child andClean:NO];
+ [self detachChild:child andClean:NO andFixNamespaces:NO];
xmlFreeNode(child);
}
2  KissXML/Private/DDXMLPrivate.h
View
@@ -187,10 +187,12 @@ NS_INLINE BOOL IsXmlNsPtr(void *kindPtr)
+ (void)removeNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node;
+ (void)removeAllNamespacesFromNode:(xmlNodePtr)node;
++ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)clean;
+ (void)detachAttribute:(xmlAttrPtr)attr;
+ (void)removeAttribute:(xmlAttrPtr)attr;
+ (void)removeAllAttributesFromNode:(xmlNodePtr)node;
++ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)clean andFixNamespaces:(BOOL)fixNamespaces;
+ (void)detachChild:(xmlNodePtr)child;
+ (void)removeChild:(xmlNodePtr)child;
+ (void)removeAllChildrenFromNode:(xmlNodePtr)node;
Please sign in to comment.
Something went wrong with that request. Please try again.