• 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: Chris Suter <email@hidden>
  • Date: Mon, 16 Jun 2008 10:50:35 +1000


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


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>)
 >Re: Issue with displaying URI prefixes on child elements using NSXML (From: Nathan Kinsinger <email@hidden>)

  • Prev by Date: Re: NSOutlineView threading problem
  • Next by Date: Re: Still trying to refactor a category as a class
  • Previous by thread: Re: Issue with displaying URI prefixes on child elements using NSXML
  • Next by thread: launchd daemon Throttling respawn log messages
  • Index(es):
    • Date
    • Thread