• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Issue with displaying URI prefixes on child elements using NSXML
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue with displaying URI prefixes on child elements using NSXML


  • Subject: Re: Issue with displaying URI prefixes on child elements using NSXML
  • From: Nathan Kinsinger <email@hidden>
  • Date: Thu, 12 Jun 2008 02:54:04 -0600


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 (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


  • Follow-Ups:
    • Re: Issue with displaying URI prefixes on child elements using NSXML
      • From: Chris Suter <email@hidden>
References: 
 >Issue with displaying URI prefixes on child elements using NSXML (From: Lawrence Johnston <email@hidden>)
 >Re: Issue with displaying URI prefixes on child elements using NSXML (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: launchd daemon Throttling respawn log messages
  • Next by Date: Re: NSTextView and changing the selected text's color
  • Previous by thread: Re: Issue with displaying URI prefixes on child elements using NSXML
  • Next by thread: Re: Issue with displaying URI prefixes on child elements using NSXML
  • Index(es):
    • Date
    • Thread