On Jun 12, 2008, at 12:48 AM, Chris Suter wrote:

The documentation says that you need to pass the qualified name in. So you need to do:

NSXMLElement *child = [NSXMLNode elementWithName:@"a:child" URI:@"http://www.tempurl.com "];

You can look-up the prefix using NSXMLElement’s resolvePrefixForNamespaceURI: method although you probably don’t need to do that.

- Chris

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.

--Nathan


_______________________________________________

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]

Reply via email to