Re: XML Attributes
Re: XML Attributes
- Subject: Re: XML Attributes
- From: Jens Alfke <email@hidden>
- Date: Sat, 3 May 2008 20:14:47 -0700
On 3 May '08, at 1:43 PM, Mr. Gecko wrote:
NSXMLNode *nodes = [xml rootElement];
NSXMLNode *node = [[nodes childAtIndex:1] childAtIndex:0];
to get this
<file url="http://www.example.com/file1" size="522656" name="File
Number 1"></file>
so now how do I get an attribute from it such as url, or name. I
saw in NSXMLElement documentation that it had an attribute thing but
I can't figure out how to convert the node to NSXMLElement to get
the attribute.
The nodes are elements. Change "NSXMLNode" to "NSXMLElement" in your
code (adding a type-cast if necessary), and then call -
attributeForName:.
If you want to learn XPath syntax (google it for lots of tutorials)
you can do all of this stuff with one or two lines of code, using -
nodesForXPath:error:; but XPath has its own learning curve.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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