On 12/06/2008, at 6:54 PM, Nathan Kinsinger wrote:
I'm curious about what using elementWithName:URI: is supposed to do
when you don't pass a qualified name in, or rather, why have it at
all? The URI seems to be redundant if you are already passing the
qualified name in.
Just as a test (from the OP's code)
NSXMLElement *root = [NSXMLNode elementWithName:@"root"];
[root addNamespace:[NSXMLNode namespaceWithName:@"a" stringValue:@"http://www.tempurl.com
"]];
NSXMLElement *child = [NSXMLNode elementWithName:@"child" URI:@"http://www.tempurl.com
"];
[child addChild:[NSXMLNode textWithStringValue:@"myText"]];
[root addChild:child];
NSXMLElement *child2 = [NSXMLNode elementWithName:@"child"];
[child2 addChild:[NSXMLNode textWithStringValue:@"myOtherText"]];
[root addChild:child2];
NSXMLElement *child3 = [NSXMLNode elementWithName:@"a:child"];
[child3 addChild:[NSXMLNode textWithStringValue:@"something
completely different"]];
[root addChild:child3];
NSLog(@"a:child = %@", [root elementsForName:@"a:child"]);
gives the result:
a:child = (
<child>myText</child>,
<a:child>something completely different</a:child>
)
So the NSXMLElement has an internal state (that the first child is
in the "a" namespace) that is not in it's XML representation? If you
were to save it and then read it back in you would lose that
information.
From the few bits of XML I've dealt with I never needed to deal with
namespaces, I'm just curious about this.
I think it’s this way because you don’t necessarily need to include
the prefix within the mark-up (the namespace can be dictated by the
default) so there needs to be a way of indicating whether or not a
prefix is included. You’re correct that you’d lose that information if
you were to save and then load it back in (so long as there’s no
default namespace). There’s the -canonicalXMLStringPreservingComments:
method that I believe will ensure that all names have prefixes.
- Chris
_______________________________________________
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 [EMAIL PROTECTED]