1

I am working on iOS application and i want to get the namespace of a nsxmlelement.

my NSXMLElement *query has the following value in it.

<query xmlns="jabber:iq:roster" test="this is value">
<item subscription="to" name="test" jid="test@local"/>
</query>

I have used following code to get the xmlns but its not working

         NSLog(@"%@",[query attributeStringValueForName:@"test"]);
         NSLog(@"%@",[query attributeStringValueForName:@"xmlns"]);

Value for test is printed but the value for xmlns shows null

Please let me know how to get the value of xmlns

Satish
  • 1,012
  • 2
  • 15
  • 32

1 Answers1

2

This is because xmlns is not an attribute. xmlns is a namespace definition. You can get it with [query namespaceForPrefix:nil].stringValue.

miho
  • 11,765
  • 7
  • 42
  • 85
  • Something additional when your are using XMPPFramework (I guess), have a look at the header file `NSXMLElement+XMPP.h`. It adds properties like `xmlns` and other very useful helpers when working with XML queries and stanzas. Makes code much easier to read, then working with NSXMLElement directly. – miho Feb 05 '14 at 10:01
  • Unless you're using a wrapper library, the above code should always return nil, because nil isn't a valid prefix value when using the NSXML API. Instead, you must pass an empty string. – dgatwood Sep 11 '14 at 18:42