KissXML
KissXML copied to clipboard
Fail to init from string - crashing
Hi,
DDXML failed to init from following fragment of XML. But NSXML handles well without any issue.
<presence xml:lang='en' from='[email protected]/XXX' to='[email protected]/XXX' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>
<show>away</show>
<status>iphone.imo.im</status>
<nick xmlns='http://jabber.org/protocol/nick'>XX XX</nick>
<c node='http://sleekxmpp.com/ver/1.2.0' ver='lTqgCk6RimJJS4ajzMjGMma0SWQ=' hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>
<x xmlns='vcard-temp:x:update'>
<photo>xxxxxxxxxxxxxxxxxx</photo>
</x>
</presence>
Test code:
NSString *str =
@"<presence xml:lang='en' from='[email protected]/XXX' to='[email protected]/XXX' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>"
@"<show>away</show>"
@"<status>iphone.imo.im</status>"
@"<nick xmlns='http://jabber.org/protocol/nick'>XX XX</nick>"
@"<c node='http://sleekxmpp.com/ver/1.2.0' ver='lTqgCk6RimJJS4ajzMjGMma0SWQ=' hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>"
@"<x xmlns='vcard-temp:x:update'>"
@"<photo>xxxxxxxxxxxxxxxxxx</photo>"
@"</x>"
@"</presence>";
NSError *error = nil;
NSXMLElement *nsBody = [[NSXMLElement alloc] initWithXMLString:str error:&error]; // pass
DDXMLElement *ddBody = [[DDXMLElement alloc] initWithXMLString:str error:&error]; // bad_access error here
It would be great if you could take a look. I'm also using XMPPFramework and this presence fragment causing crash.
Thank you! -Thant
Hi, I am experiencing the same problem. It arises while using the MessageArchiving module from the XMPPFramework. There is a class XMPPMessageArchiving_Message_CoreDataObject that creates XMPPMessage object from the xml string using KissXML. The message object contains localized body with "xml:lang" attribute. The DDXMLNode's class method + (void)recursiveFixDefaultNamespacesInNode:(xmlNodePtr)node withNewRoot:(xmlNodePtr)rootNode copying the namespace while his 2 step. It uses xmlNewNs function, and it returns NULL because of "xml" prefix, provided to it, as I found here http://www.opensource.apple.com/source/libxml2/libxml2-8/libxml2/tree.c . After that there is an exc_bad_access in the line "attrNsCopy->next = node->nsDef;". Hope this will help.
In case anyone encounters this too, I have found a workaround by creating DDXMLDocument object instead:
guard let ddDocument = try? DDXMLDocument(xmlString: xmlString, options: 0),
let ddElement = ddDocument.rootElement() else {
return nil
}
// use ddElement here