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

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 29, 2009, 07:58 PM   #1
Chirone
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

Code:
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
Code:
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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPad Mini: Anyone switch from reading on a Paperwhite to reading on the rMini? Frankied22 iPad 48 May 23, 2014 01:16 AM
Mp3 file attributes cool11 Digital Audio 0 Oct 17, 2013 01:02 PM
PDF Attributes simple tool for editing PDF attributes Alex Aperio Lux Mac Applications and Mac App Store 0 Apr 8, 2013 04:17 PM
Free app for offline reading (only reading ) PDF, WORD, EXCEL, PPT files Subu iPhone and iPod touch Apps 0 Feb 21, 2013 10:43 PM
Removing document attributes/metadata gax23 OS X 1 Aug 21, 2012 02:40 AM

Forum Jump

All times are GMT -5. The time now is 05:27 AM.

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

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