Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #12 from davydotcom/patch-1

Fixed Missing Content issue with HTML. Now all elements with tagName == ...
  • Loading branch information...
commit ab1a51b3701a2ae25628df73b157ab074d586cde 2 parents 7dc8f6f + 7f15c4b
@topfunky authored
Showing with 19 additions and 12 deletions.
  1. +19 −12 XPathQuery.m
View
31 XPathQuery.m
@@ -14,10 +14,10 @@
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>
-NSDictionary *DictionaryForNode(xmlNodePtr currentNode, NSMutableDictionary *parentResult);
+NSDictionary *DictionaryForNode(xmlNodePtr currentNode, NSMutableDictionary *parentResult,BOOL parentContent);
NSArray *PerformXPathQuery(xmlDocPtr doc, NSString *query);
-NSDictionary *DictionaryForNode(xmlNodePtr currentNode, NSMutableDictionary *parentResult)
+NSDictionary *DictionaryForNode(xmlNodePtr currentNode, NSMutableDictionary *parentResult,BOOL parentContent)
{
NSMutableDictionary *resultForNode = [NSMutableDictionary dictionary];
@@ -35,15 +35,21 @@
if ([[resultForNode objectForKey:@"nodeName"] isEqual:@"text"] && parentResult)
{
- [parentResult
- setObject:
- [currentNodeContent
- stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]
- forKey:@"nodeContent"];
- return nil;
+ if(parentContent)
+ {
+ [parentResult setObject:[currentNodeContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:@"nodeContent"];
+ return nil;
+ }
+ [resultForNode setObject:currentNodeContent forKey:@"nodeContent"];
+// NSLog(@"content: %@",currentNodeContent);
+ return resultForNode;
+
}
+ else {
+ [resultForNode setObject:currentNodeContent forKey:@"nodeContent"];
+ }
+
- [resultForNode setObject:currentNodeContent forKey:@"nodeContent"];
}
xmlAttr *attribute = currentNode->properties;
@@ -57,12 +63,13 @@
[NSString stringWithCString:(const char *)attribute->name encoding:NSUTF8StringEncoding];
if (attributeName)
{
+// NSLog(@"Attribute Name Set: %@",attributeName);
[attributeDictionary setObject:attributeName forKey:@"attributeName"];
}
if (attribute->children)
{
- NSDictionary *childDictionary = DictionaryForNode(attribute->children, attributeDictionary);
+ NSDictionary *childDictionary = DictionaryForNode(attribute->children, attributeDictionary,true);
if (childDictionary)
{
[attributeDictionary setObject:childDictionary forKey:@"attributeContent"];
@@ -88,7 +95,7 @@
NSMutableArray *childContentArray = [NSMutableArray array];
while (childNode)
{
- NSDictionary *childDictionary = DictionaryForNode(childNode, resultForNode);
+ NSDictionary *childDictionary = DictionaryForNode(childNode, resultForNode,false);
if (childDictionary)
{
[childContentArray addObject:childDictionary];
@@ -137,7 +144,7 @@
NSMutableArray *resultNodes = [NSMutableArray array];
for (NSInteger i = 0; i < nodes->nodeNr; i++)
{
- NSDictionary *nodeDictionary = DictionaryForNode(nodes->nodeTab[i], nil);
+ NSDictionary *nodeDictionary = DictionaryForNode(nodes->nodeTab[i], nil,false);
if (nodeDictionary)
{
[resultNodes addObject:nodeDictionary];
Please sign in to comment.
Something went wrong with that request. Please try again.