can't extract first element's attributes #7

Closed
justgig8 opened this Issue Feb 25, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@justgig8

This code doesn't work!

NSData* data=[xml dataUsingEncoding: NSUTF8StringEncoding];
SMXMLDocument *document = [SMXMLDocument documentWithData:data error:nil];
SMXMLElement *response = [document.root childNamed:@"response"];
NSLog(@"element: %@", response);
NSLog(@"response type: %@", [response attributeNamed:@"type"]);

when my xml is as follows:-

2012-02-25 13:33:50

@justgig8

This comment has been minimized.

Show comment Hide comment
@justgig8

justgig8 Feb 25, 2012

Does it IGNORE the topmost root element of every XML? coz even in the books example.. it is not parsing tag!

Does it IGNORE the topmost root element of every XML? coz even in the books example.. it is not parsing tag!

@nfarina

This comment has been minimized.

Show comment Hide comment
@nfarina

nfarina Feb 25, 2012

Owner

When you type:

SMXMLElement *response = [document.root childNamed:@"response"];

What you're doing is asking the root node for its child. So the result of this function is empty, because the <response> node doesn't contain another child named <response>.

Instead you should write:

SMXMLElement *response = document.root;
Owner

nfarina commented Feb 25, 2012

When you type:

SMXMLElement *response = [document.root childNamed:@"response"];

What you're doing is asking the root node for its child. So the result of this function is empty, because the <response> node doesn't contain another child named <response>.

Instead you should write:

SMXMLElement *response = document.root;
@justgig8

This comment has been minimized.

Show comment Hide comment
@justgig8

justgig8 Feb 25, 2012

Am sorry for that!
I love all of your code here.
Next am checking the http web request one.

Thanks a lot! :)

Am sorry for that!
I love all of your code here.
Next am checking the http web request one.

Thanks a lot! :)

@justgig8 justgig8 closed this Feb 25, 2012

@nfarina

This comment has been minimized.

Show comment Hide comment
@nfarina

nfarina Feb 25, 2012

Owner

My pleasure, glad to be of help =)

Owner

nfarina commented Feb 25, 2012

My pleasure, glad to be of help =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment