Re: Issue with displaying URI prefixes on child elements using NSXML
Re: Issue with displaying URI prefixes on child elements using NSXML
- Subject: Re: Issue with displaying URI prefixes on child elements using NSXML
- From: Lawrence Johnston <email@hidden>
- Date: Thu, 12 Jun 2008 00:45:29 -0700
It all makes sense now. Thanks.
On Jun 11, 2008, at 11:48 PM, Chris Suter wrote:
On 11/06/2008, at 3:19 PM, Lawrence Johnston wrote:
Hey everybody, I've got an issue that I can't figure out.
If I'm using this code:
NSString *XMLForDisplay {
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];
return [root XMLStringWithOptions:NSXMLNodePrettyPrint];
}
I believe it should be outputting this text:
<root xmlns:a="http://www.tempurl.com">
<a:child>myText</a:child>
</root>
However, instead it outputs this text (note the lack of prefix on
the child):
<root xmlns:a="http://www.tempurl.com">
<child>myText</child>
</root>
This is an issue, because I need that "a:" prefix.
The documentation for elementWithName:URI: states it's equivalent
to <URI:name></URI:name>, which is exactly what I want, except that
I can't get it to display that way.
Thanks for your time.
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
_______________________________________________
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