Skip to content

Commit a23d6b2

Browse files
committed
Remove NSXMLElement APIs
1 parent 9cadf46 commit a23d6b2

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Categories/NSXMLElement+XMPP.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
- (NSXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns;
3333
- (NSXMLElement *)elementForName:(NSString *)name xmlnsPrefix:(NSString *)xmlnsPrefix;
3434

35+
/**
36+
* Convenience methods for removing child elements.
37+
*
38+
* If the element doesn't exist, these methods do nothing.
39+
**/
40+
41+
- (void)removeElementForName:(NSString *)name;
42+
- (void)removeElementsForName:(NSString *)name;
43+
- (void)removeElementForName:(NSString *)name xmlns:(NSString *)xmlns;
44+
- (void)removeElementForName:(NSString *)name xmlnsPrefix:(NSString *)xmlnsPrefix;
45+
3546
/**
3647
* Working with the common xmpp xmlns value.
3748
*

Categories/NSXMLElement+XMPP.m

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,62 @@ - (NSXMLElement *)elementForName:(NSString *)name xmlnsPrefix:(NSString *)xmlnsP
140140
return result;
141141
}
142142

143+
/**
144+
* This method removes the first child element for the given name.
145+
* If no child elements exist for the given name, this method does nothing.
146+
**/
147+
- (void)removeElementForName:(NSString *)name
148+
{
149+
NSXMLElement *element = [self elementForName:name];
150+
151+
if(element)
152+
{
153+
[self removeChildAtIndex:[[self children] indexOfObject:element]];
154+
}
155+
}
156+
157+
/**
158+
* This method removes the all child elements for the given name.
159+
* If no child elements exist for the given name, this method does nothing.
160+
**/
161+
- (void)removeElementsForName:(NSString *)name
162+
{
163+
NSArray *elements = [self elementsForName:name];
164+
165+
for(NSXMLElement *element in elements)
166+
{
167+
[self removeChildAtIndex:[[self children] indexOfObject:element]];
168+
}
169+
}
170+
171+
/**
172+
* This method removes the first child element for the given name and given xmlns.
173+
* If no child elements exist for the given name and given xmlns, this method does nothing.
174+
**/
175+
- (void)removeElementForName:(NSString *)name xmlns:(NSString *)xmlns
176+
{
177+
NSXMLElement *element = [self elementForName:name xmlns:xmlns];
178+
179+
if(element)
180+
{
181+
[self removeChildAtIndex:[[self children] indexOfObject:element]];
182+
}
183+
}
184+
185+
/**
186+
* This method removes the first child element for the given name and given xmlns prefix.
187+
* If no child elements exist for the given name and given xmlns prefix, this method does nothing.
188+
**/
189+
- (void)removeElementForName:(NSString *)name xmlnsPrefix:(NSString *)xmlnsPrefix
190+
{
191+
NSXMLElement *element = [self elementForName:name xmlnsPrefix:xmlnsPrefix];
192+
193+
if(element)
194+
{
195+
[self removeChildAtIndex:[[self children] indexOfObject:element]];
196+
}
197+
}
198+
143199
/**
144200
* Returns the common xmlns "attribute", which is only accessible via the namespace methods.
145201
* The xmlns value is often used in jabber elements.

0 commit comments

Comments
 (0)