XPath Namespace issues

Bruce Lee Jr.

New Member
When connecting to an XMPP server I get one of these two responses:\[code\]<stream:features xmlns:stream="http://etherx.jabber.org/streams"> <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"> <mechanism>PLAIN</mechanism> <mechanism>DIGEST MD5</mechanism> </mechanisms> <auth xmlns="http://jabber.org/features/iq-auth" /> <register xmlns="http://jabber.org/features/iq-register" /></stream:features>\[/code\]OR\[code\]<stream:features> <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"> <mechanism>DIGEST-MD5</mechanism> <mechanism>PLAIN</mechanism> <mechanism>ANONYMOUS</mechanism> <mechanism>CRAM-MD5</mechanism> </mechanisms> <compression xmlns="http://jabber.org/features/compress"> <method>zlib</method> </compression> <auth xmlns="http://jabber.org/features/iq-auth" /> <register xmlns="http://jabber.org/features/iq-register" /></stream:features>\[/code\]When trying to parse the second one with my code, I get this error:\[code\]namespace error : Namespace prefix stream on features is not defined<stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism ^\[/code\]Here is my code:\[code\]mechanisms = []xmlParsed = libxml2.parseDoc(xmlResponse)xpathContext = xmlParsed.xpathNewContext()xpathContext.xpathRegisterNs('urn','http://etherx.jabber.org/streams')xpathContext.xpathRegisterNs('sasl', 'urn:ietf:params:xml:ns:xmpp-sasl')nodes = xpathContext.xpathEval("//urn:stream/features/sasl:mechanisms/sasl:mechanism/text()|//urn:features/sasl:mechanisms/sasl:mechanism/text()")for node in nodes: mechanisms.append(str(node))\[/code\]What am I doing wrong and how can I right it? Please don't say, use the XMPP libraries or such, I'm not trying to write an entire XMPP client. I just want enough code to register as a user first.
 
Back
Top