Re: nodesForXPath almost always returns no objects
Re: nodesForXPath almost always returns no objects
- Subject: Re: nodesForXPath almost always returns no objects
- From: Justin Anderson <email@hidden>
- Date: Tue, 9 Jan 2007 17:14:44 -0500
Even more interesting is when you load that XML into /Developer/
Examples/Foundation/XMLBrowser/. When you navigate the XML tree in
the Editor tab, it shows the XPath that gets you the selected
element, but if you copy FindMembershipResponse's reported XPath into
the XQuery tab, you get no results.
I'm guessing this is a bug in how NSXML deals with the xmlns
attribute. Or perhaps it's a bug in libxml itself, but I doubt that.
Justin Anderson
On Jan 9, 2007, at 5:04 PM, Ryan Homer wrote:
Thanks for the information, Klaus.
Do you know what XPath query I could use to navigate the document?
When I try the following, it returns no elements:
NSXMLNode *n = [xmldoc rootElement];
NSArray *a = [n nodesForXPath:@"//soap:Body/
FindMembershipResponse" error:&error];
According to Stephen, the XPath query works without the xmlns
parameter. Is there some change in the XPath query string to
accommodate for this?
Ryan
On 9-Jan-07, at 3:27 PM, Klaus Backert wrote:
Am 09.01.2007 um 16:03 schrieb Ryan Homer:
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table
So, they are defining a namespace called "h". In my example, it is:
<FindMembershipResponse xmlns="http://www.msn.com/webservices/
AddressBook">
Does anyone know the difference? If we're not defining a new
namespace, why the xmlns tag?
Ryan
If the attribute is xmlns - and *not* xmlns: followed by an XML
name -, then the namespace name in the attribute value is that of
the default namespace in the scope to which the declaration is
attached.
See <http://www.w3.org/TR/1999/REC-xml-names-19990114/>.
An example from this W3C recommendation:
<?xml version="1.0"?>
<!-- elements are in the HTML namespace, in this case by default -->
<html xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Frobnostication</title></head>
<body><p>Moved to
<a href='http://frob.com'>here</a>.</p></body>
</html>
<FindMembershipResponse xmlns="http://www.msn.com/webservices/
AddressBook">
sets the default namespace name to <http://www.msn.com/webservices/
AddressBook> (angle brackets for readability only). Then all
elements with no prefix within the content of the element
FindMembershipResponse belong to this default namespace.
Klaus
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40mac.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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