Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed Missing Content issue with HTML. Now all elements with tagName == ... #12

Merged
merged 1 commit into from

2 participants

@davydotcom

...'text' are children with textual content. This had to be done as text was getting wiped out as the result of the current implementation

@davydotcom davydotcom Fixed Missing Content issue with HTML. Now all elements with tagName …
…== 'text' are children with textual content. This had to be done as text was getting wiped out as the result of the current implementation
7f15c4b
@topfunky topfunky merged commit ab1a51b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2012
  1. @davydotcom

    Fixed Missing Content issue with HTML. Now all elements with tagName …

    davydotcom authored
    …== 'text' are children with textual content. This had to be done as text was getting wiped out as the result of the current implementation
This page is out of date. Refresh to see the latest.
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];
Something went wrong with that request. Please try again.