Can NSXMLParser be used to parse XMPP messages?

282 views Asked by At

XMPP uses some odd styling, for example:

<stream:stream to='domain.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>

When calling parse.() on this XML data, it returns false. There are 2 problems that I could see be causing this:

  1. Does not have </stream> tag
  2. <stream:stream contains a semi colon.

Can NSXMLParser be used to parse this? On GitHub, I saw other people built their own parser, but I don't think it will be as accurate as NSXMLParser provided, if it worked.

1

There are 1 answers

2
ldindu On BEST ANSWER

It can be parsed by NSXMLParser as the NSXMLParser conforms to NSXMLParserDelegate protocol which implements certain callback delegate methods such as

 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
        namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
        attributes:(NSDictionary *)attributeDict

and

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
       namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName

which allows you to parse when the parser encounters opening/closing tags.

Colon ':' inside the tag might not stop you from what you want to achieve. And you doesn't have to worry about missing closing tag as by then you will be responding to didStartElement callback method only