Re: Proper way to construct an Attribute NSXMLNode so that its prefix is included in its XMLString
Re: Proper way to construct an Attribute NSXMLNode so that its prefix is included in its XMLString
- Subject: Re: Proper way to construct an Attribute NSXMLNode so that its prefix is included in its XMLString
- From: Matt Neuburg <email@hidden>
- Date: Mon, 07 Mar 2011 18:56:42 -0800
>Thus, I do the following:
>
>NSXMLElement rootXmlElement = ...
>NSXMLNode *schemaLocationAttributeXmlNode =
> [NSXMLNode attributeWithName:@"schemaLocation" URI:@"xsi"
>stringValue:@"http://example.com/document document.xsd"];
>So, now, I tried specifying the prefix in the attribute name when
>creating the attribute:
>
>NSXMLElement rootXmlElement = ...
>NSXMLNode *schemaLocationAttributeXmlNode =
> [NSXMLNode attributeWithName:@"xsi:schemaLocation"
>URI:@"http://www.w3.org/2001/XMLSchema-instance"
>stringValue:@"http://example.com/document document.xsd"];
>
>[rootXmlElement addAttribute:schemaLocationAttributeXmlNode];
>
>Success!
>This doesn't seem consistent with the documentation.
They haven't made it terribly clear, have they? I would have done it like this:
NSXMLElement* e = [[NSXMLElement alloc] initWithName: @"document"];
NSXMLNode* def = [NSXMLNode namespaceWithName:@""
stringValue:@"http://example.com/document"];
[e addNamespace:def];
NSXMLNode* xsi = [NSXMLNode predefinedNamespaceForPrefix:@"xsi"];
[e addNamespace:xsi];
NSXMLNode* loc = [NSXMLNode attributeWithName:@"xsi:schemaLocation"
stringValue:@"http://example.com/document document.xsd"];
[e addAttribute: loc];
But that does leave one wondering what the URI param is for...
m.
--
matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook_______________________________________________
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