Skip to content
This repository

Added nodeForXpath:namespaceMapping:error method #26

Merged
merged 1 commit into from 4 months ago

2 participants

Pierre-Yves LEBECQ Jonathan Wight
Pierre-Yves LEBECQ

Hello there,

I'm writing an iOS application parsing some XML with many namespaces and I've been looking very often for single nodes in my XML documents.

I was told to use the method nodesForXpath:namespaceMappings:error: method to work with namespaces, and I found out the nodeForXpath:error: method not resolving the namespaces but returning a single node instead of an array. So I ended up writing a similar method but resolving namespaces as well.

I also took the liberty of changing the @implementation statement to match the one in the header file and in the filenames.

I'm completely new to Objective-C so please tell me if I did something wrong.

Regards.

Jonathan Wight schwa merged commit 391d93c into from
Jonathan Wight schwa closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 15, 2012
Pierre-Yves LEBECQ pylebecq [CXMLNode_XPathExtensions] Added a convenient method to retrieve a si…
…ngle node with namespace mapping.
e84bc8d
This page is out of date. Refresh to see the latest.
1  Source/CXMLNode_XPathExtensions.h
@@ -34,6 +34,7 @@
34 34 @interface CXMLNode (CXMLNode_XPathExtensions)
35 35
36 36 - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error;
  37 +- (CXMLNode *)nodeForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error;
37 38 - (CXMLNode *)nodeForXPath:(NSString *)xpath error:(NSError **)outError;
38 39
39 40 @end
7 Source/CXMLNode_XPathExtensions.m
@@ -37,7 +37,7 @@
37 37 #include <libxml/xpath.h>
38 38 #include <libxml/xpathInternals.h>
39 39
40   -@implementation CXMLNode (CXMLNode_NamespaceExtensions)
  40 +@implementation CXMLNode (CXMLNode_XPathExtensions)
41 41
42 42 - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error;
43 43 {
@@ -78,6 +78,11 @@ - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)i
78 78 return(theResult);
79 79 }
80 80
  81 +- (CXMLNode *)nodeForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error
  82 +{
  83 + return [[self nodesForXPath:xpath namespaceMappings:inNamespaceMappings error:error] lastObject];
  84 +}
  85 +
81 86 - (CXMLNode *)nodeForXPath:(NSString *)xpath error:(NSError **)outError
82 87 {
83 88 return([[self nodesForXPath:xpath error:outError] lastObject]);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.