Skip to content

Commit 1a8ae62

Browse files
committed
Adding ability to detach a child node without bothering to fix the namespaces.
1 parent 0044ccd commit 1a8ae62

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

KissXML/DDXMLNode.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ + (void)removeAllNamespacesFromNode:(xmlNodePtr)node
17391739
* The attribute's surrounding prev/next pointers are properly updated to remove the attribute from the attr list.
17401740
* Then, if the clean flag is YES, the attribute's parent, prev, next and doc pointers are set to null.
17411741
**/
1742-
+ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)flag
1742+
+ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)clean
17431743
{
17441744
xmlNodePtr parent = attr->parent;
17451745

@@ -1769,7 +1769,7 @@ + (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)flag
17691769
}
17701770
}
17711771

1772-
if (flag)
1772+
if (clean)
17731773
{
17741774
// Nullify pointers
17751775
attr->parent = NULL;
@@ -1834,7 +1834,7 @@ + (void)removeAllAttributesFromNode:(xmlNodePtr)node
18341834
* The child's surrounding prev/next pointers are properly updated to remove the child from the node's children list.
18351835
* Then, if the clean flag is YES, the child's parent, prev, next and doc pointers are set to null.
18361836
**/
1837-
+ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag
1837+
+ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)clean andFixNamespaces:(BOOL)fixNamespaces
18381838
{
18391839
xmlNodePtr parent = child->parent;
18401840

@@ -1866,11 +1866,14 @@ + (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag
18661866
}
18671867
}
18681868

1869-
if (flag)
1869+
if (fixNamespaces)
18701870
{
18711871
// Fix namesapces (namespace references that now point outside tree)
1872+
// Note: This must be done before we nullify pointers so we can search up the tree.
18721873
[self recursiveFixDefaultNamespacesInNode:child withNewRoot:child];
1873-
1874+
}
1875+
if (clean)
1876+
{
18741877
// Nullify pointers
18751878
child->parent = NULL;
18761879
child->prev = NULL;
@@ -1886,7 +1889,7 @@ + (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag
18861889
**/
18871890
+ (void)detachChild:(xmlNodePtr)child
18881891
{
1889-
[self detachChild:child andClean:YES];
1892+
[self detachChild:child andClean:YES andFixNamespaces:YES];
18901893
}
18911894

18921895
/**
@@ -1905,7 +1908,7 @@ + (void)removeChild:(xmlNodePtr)child
19051908

19061909
// We perform a bit of optimization here.
19071910
// No need to bother nullifying pointers since we're about to free the node anyway.
1908-
[self detachChild:child andClean:NO];
1911+
[self detachChild:child andClean:NO andFixNamespaces:NO];
19091912

19101913
xmlFreeNode(child);
19111914
}

KissXML/Private/DDXMLPrivate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ NS_INLINE BOOL IsXmlNsPtr(void *kindPtr)
187187
+ (void)removeNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node;
188188
+ (void)removeAllNamespacesFromNode:(xmlNodePtr)node;
189189

190+
+ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)clean;
190191
+ (void)detachAttribute:(xmlAttrPtr)attr;
191192
+ (void)removeAttribute:(xmlAttrPtr)attr;
192193
+ (void)removeAllAttributesFromNode:(xmlNodePtr)node;
193194

195+
+ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)clean andFixNamespaces:(BOOL)fixNamespaces;
194196
+ (void)detachChild:(xmlNodePtr)child;
195197
+ (void)removeChild:(xmlNodePtr)child;
196198
+ (void)removeAllChildrenFromNode:(xmlNodePtr)node;

0 commit comments

Comments
 (0)