Re: XML Namespace Definitions on Non-Root Elements

2011-03-07 Thread Matt Neuburg
Very cool, but I do suggest you file a bug. Apple's XPath interface falls short 
with regard to namespaces. Contrast, for example, Nokogiri which lets you pass 
namespace info into an XPath query, or Microsoft with its XML Namespace Manager 
class. In other words, XPath does know about namespaces, but Apple gives you no 
direct way to tap into this part of its knowledge - a node knows about 
namespace nodes attached to *it*, and supplies these implicitly for any XPath 
queries performed on it (as you discovered) but that's all. This is just wrong. 
Your example is an excellent case in point. m.

On Mon, 07 Mar 2011 09:40:38 -0600, Heath Borders  
said:
>That worked!
>
>I actually changed it to:
>
>nodesForXPath:@"/root/*[name() = \"example:foo\"]
>
>Thanks!
>
>-Heath Borders
>heath.bord...@gmail.com
>Twitter: heathborders
>http://heath-tech.blogspot.com
>
>
>
>On Sat, Mar 5, 2011 at 2:27 PM, Matt Neuburg  wrote:
>> On Fri, 04 Mar 2011 14:25:06 -0600, Heath Borders  
>> said:
>>>I'm trying to parse a document with a namespace declared on a non-root 
>>>element:
>>>
>>>http://example.com/foo";>This is an
>>>exemplary foo!
>>>
>>>I can read this xml into an NSXMLDocument just fine, but the following
>>>XPath query on root returns a non-nil, but empty NSArray:
>>>
>>>NSXMLNode *rootNode = ...// create my root node somehow
>>>NSArray *exampleFooElements = [rootNode
>>>nodesForXPath:@"/root/example:foo" error:nil];
>>>// exampleFooElements != nil && [exampleFooElements count] == 0
>>>
>>>However, if I add the namespace declaration to the root element,
>>>everything is fine:
>>>
>>>http://example.com/foo";>This is an
>>>exemplary foo!
>>>
>>>NSXMLNode *rootNode = ...// create my root node somehow
>>>NSArray *exampleFooElements = [rootNode
>>>nodesForXPath:@"/root/example:foo" error:nil];
>>>// exampleFooElements != nil && [exampleFooElements count] == 1
>>>
>>>I can do this change programmatically, but I'd rather not have to
>>>modify the document. Â This namespace usage should be legal. Â Am I
>>>doing something wrong?
>>
>> It's no use just saying "example:"; you have to have a way to tell it what 
>> "example:" *is* - i.e. you have to bind the namespace - and you don't have a 
>> way to do that from here. One option is to bypass the namespace altogether:
>>
>>  nodesForXPath:@"//*[local-name()='foo']"
>>

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: XML Namespace Definitions on Non-Root Elements

2011-03-07 Thread Heath Borders
That worked!

I actually changed it to:

nodesForXPath:@"/root/*[name() = \"example:foo\"]

Thanks!

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com



On Sat, Mar 5, 2011 at 2:27 PM, Matt Neuburg  wrote:
> On Fri, 04 Mar 2011 14:25:06 -0600, Heath Borders  
> said:
>>I'm trying to parse a document with a namespace declared on a non-root 
>>element:
>>
>>http://example.com/foo";>This is an
>>exemplary foo!
>>
>>I can read this xml into an NSXMLDocument just fine, but the following
>>XPath query on root returns a non-nil, but empty NSArray:
>>
>>NSXMLNode *rootNode = ...// create my root node somehow
>>NSArray *exampleFooElements = [rootNode
>>nodesForXPath:@"/root/example:foo" error:nil];
>>// exampleFooElements != nil && [exampleFooElements count] == 0
>>
>>However, if I add the namespace declaration to the root element,
>>everything is fine:
>>
>>http://example.com/foo";>This is an
>>exemplary foo!
>>
>>NSXMLNode *rootNode = ...// create my root node somehow
>>NSArray *exampleFooElements = [rootNode
>>nodesForXPath:@"/root/example:foo" error:nil];
>>// exampleFooElements != nil && [exampleFooElements count] == 1
>>
>>I can do this change programmatically, but I'd rather not have to
>>modify the document.  This namespace usage should be legal.  Am I
>>doing something wrong?
>
> It's no use just saying "example:"; you have to have a way to tell it what 
> "example:" *is* - i.e. you have to bind the namespace - and you don't have a 
> way to do that from here. One option is to bypass the namespace altogether:
>
>  nodesForXPath:@"//*[local-name()='foo']"
>
> m.
>
>
> --
> matt neuburg, phd = m...@tidbits.com, 
> A fool + a tool + an autorelease pool = cool!
> Programming iOS 4!
> http://www.apeth.net/matt/default.html#iosbook
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: XML Namespace Definitions on Non-Root Elements

2011-03-05 Thread Matt Neuburg
On Fri, 04 Mar 2011 14:25:06 -0600, Heath Borders  
said:
>I'm trying to parse a document with a namespace declared on a non-root element:
>
>http://example.com/foo";>This is an
>exemplary foo!
>
>I can read this xml into an NSXMLDocument just fine, but the following
>XPath query on root returns a non-nil, but empty NSArray:
>
>NSXMLNode *rootNode = ...// create my root node somehow
>NSArray *exampleFooElements = [rootNode
>nodesForXPath:@"/root/example:foo" error:nil];
>// exampleFooElements != nil && [exampleFooElements count] == 0
>
>However, if I add the namespace declaration to the root element,
>everything is fine:
>
>http://example.com/foo";>This is an
>exemplary foo!
>
>NSXMLNode *rootNode = ...// create my root node somehow
>NSArray *exampleFooElements = [rootNode
>nodesForXPath:@"/root/example:foo" error:nil];
>// exampleFooElements != nil && [exampleFooElements count] == 1
>
>I can do this change programmatically, but I'd rather not have to
>modify the document.  This namespace usage should be legal.  Am I
>doing something wrong?

It's no use just saying "example:"; you have to have a way to tell it what 
"example:" *is* - i.e. you have to bind the namespace - and you don't have a 
way to do that from here. One option is to bypass the namespace altogether:

  nodesForXPath:@"//*[local-name()='foo']"

m.


--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


XML Namespace Definitions on Non-Root Elements

2011-03-04 Thread Heath Borders
I'm trying to parse a document with a namespace declared on a non-root element:

http://example.com/foo";>This is an
exemplary foo!

I can read this xml into an NSXMLDocument just fine, but the following
XPath query on root returns a non-nil, but empty NSArray:

NSXMLNode *rootNode = ...// create my root node somehow
NSArray *exampleFooElements = [rootNode
nodesForXPath:@"/root/example:foo" error:nil];
// exampleFooElements != nil && [exampleFooElements count] == 0

However, if I add the namespace declaration to the root element,
everything is fine:

http://example.com/foo";>This is an
exemplary foo!

NSXMLNode *rootNode = ...// create my root node somehow
NSArray *exampleFooElements = [rootNode
nodesForXPath:@"/root/example:foo" error:nil];
// exampleFooElements != nil && [exampleFooElements count] == 1

I can do this change programmatically, but I'd rather not have to
modify the document.  This namespace usage should be legal.  Am I
doing something wrong?

Thanks!

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com