• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
XML Namespace Definitions on Non-Root Elements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

XML Namespace Definitions on Non-Root Elements


  • Subject: XML Namespace Definitions on Non-Root Elements
  • From: Heath Borders <email@hidden>
  • Date: Fri, 04 Mar 2011 14:25:06 -0600

I'm trying to parse a document with a namespace declared on a non-root element:

<root><example:foo xmlns:example="http://example.com/foo";>This is an
exemplary foo!</example:foo></root>

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:

<root xmlns:example="http://example.com/foo";><example:foo>This is an
exemplary foo!</example:foo></root>

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
email@hidden
Twitter: heathborders
http://heath-tech.blogspot.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: NSAttributedString crashes
  • Next by Date: Re: -[NSSet containsObject:] returns NO when it should return YES
  • Previous by thread: Re: Accepting current edited text field contents
  • Next by thread: Re: XML Namespace Definitions on Non-Root Elements
  • Index(es):
    • Date
    • Thread