Skip to content

Commit e3dde8c

Browse files
Fix issue with newer versions of libxml2
1 parent 7b9c2fc commit e3dde8c

14 files changed

+1332
-24
lines changed

Source/NSXMLElement.m

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,42 @@ - (NSArray*) elementsForName: (NSString*)name
163163
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
164164
xmlNodePtr cur = NULL;
165165
const xmlChar *xmlName = XMLSTRING(name);
166-
166+
xmlNsPtr defaultNS = NULL;
167+
168+
// Find the default namespace (empty or NULL prefix) of this parent element
169+
xmlNsPtr ns;
170+
for (ns = internal->node.node->nsDef; ns != NULL; ns = ns->next)
171+
{
172+
if (ns->prefix == NULL || xmlStrcmp(ns->prefix, (const xmlChar*)"") == 0)
173+
{
174+
defaultNS = ns;
175+
break;
176+
}
177+
}
178+
167179
for (cur = internal->node.node->children; cur != NULL; cur = cur->next)
168180
{
169181
if (cur->type == XML_ELEMENT_NODE)
170182
{
171-
// no namespace or default namespace
172-
if ((xmlStrcmp(xmlName, cur->name) == 0) &&
173-
((cur->ns == NULL) || (cur->ns->prefix == NULL) ||
174-
(xmlStrcmp(cur->ns->prefix, (const xmlChar*)"") == 0)))
183+
if (xmlStrcmp(xmlName, cur->name) == 0)
175184
{
176-
NSXMLNode *theNode = [NSXMLNode _objectForNode: cur];
177-
[results addObject: theNode];
185+
// Match elements with no namespace
186+
if (cur->ns == NULL)
187+
{
188+
NSXMLNode *theNode = [NSXMLNode _objectForNode: cur];
189+
[results addObject: theNode];
190+
}
191+
// Match elements in the default namespace if one exists
192+
else if (defaultNS != NULL && cur->ns->href != NULL &&
193+
xmlStrcmp(cur->ns->href, defaultNS->href) == 0)
194+
{
195+
NSXMLNode *theNode = [NSXMLNode _objectForNode: cur];
196+
[results addObject: theNode];
197+
}
178198
}
179199
}
180200
}
181-
201+
182202
return results;
183203
}
184204
}

0 commit comments

Comments
 (0)