Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jul 29, 2009, 07:58 PM   #1
macrumors 6502
Join Date: Mar 2009
Location: NZ
XML attributes and reading what they are

ok, this is going to sound really stupid...

i can add an attribute to a node easily enough and append it to another node

NSXMLNode* attr = [[NSXMLNode alloc] initWithKind: NSXMLAttributeKind];
[attr setName: @"testAttr"];
[attr setStringValue: @"testVal"];
[root addChild: [NSXMLNode elementWithName: @"testNode" children: nil attributes: [NSArray arrayWithObject: attr]]];
easy, and it appears as i'd expect

now... how do i read that value back (specifically from a file, not when i just created it)?
I saw that you can get/set attribute values for an NSXMLElement which is a subclass of NSXMLNode

so how do i get the attributes of an NSXMLNode?

eeeh, nevermind, i missed the part where NSXMLDocument returns an NSXMLElement when you call rootNode

oh wait, that's right... NodesForXPath returns an NSArray of NSXMLNode

is it possible to get the attribute name and value from an NSXMLNode?

pfff, i knew this was a stupid question! just needed a few minutes to experiment more

found me what i was after
NSXMLNode* rootTwo = [xmlDoc rootElement];
NSArray* pathNodes = [rootTwo nodesForXPath:@"/singQToRenderQ/testNode" error: nil];
NSXMLElement* elementNode = [pathNodes objectAtIndex: 0];
NSArray* attributesFromElement = [elementNode attributes];
NSXMLNode* theAttributeNode = [elementNode attributeForName: @"testAttr"];

Last edited by Chirone; Jul 29, 2009 at 08:35 PM.
Chirone is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
What??? They are removing Unlimited Data?? greytmom iPhone 2 Oct 7, 2011 03:25 AM
When I Go To Youtube And Watch Videos They Are Very Slow, Audio Is Fine, Please Help? petedogz Mac Basics and Help 5 Jan 18, 2010 12:25 PM
Mac os x installation problems. Anyone know what they are doing? Please help!! Ashleyhall19 OS X 13 Aug 8, 2009 06:31 PM
Bindings - would someone explain what they are? glossywhite iPhone/iPad Programming 8 Apr 6, 2009 07:01 PM
why Jobs is Jobs and how computers became what they are today. sillycybin General Mac Discussion 11 Jan 22, 2006 11:06 AM

All times are GMT -5. The time now is 04:32 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC