On 2/25/2010 10:59 AM, Jan Dinger wrote:
Hello folks,
I've a problem to create a xml struct like XMPP. XMPP has a lot of
namspaces and prefixes, so xercesc ist a good choice for creating and
parsing XMPP snippets.
I'll create a XML like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<stream:stream xmlns:stream="http://etherx.jabber.org/streams">
<stream:error>
<error xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
</stream:error>
</stream:stream>
The stream:stream tag and namespace is no problem, this will do the
Document constructor.
But the stream:error and the namspace at the error element is tricky.
Here some code witch fail:
### snip ###
DOMElement* stream_error_elem = doc->createElement(X("error"));
stream_error_elem->setPrefix("X("stream"));
### snap ###
These construct will fail with an error: attempt is made to create or
change an object in a way which is incorrect with respect to
namespaces
You need to use either the createElement() and createAttribute() factory
functions, or the createElementNS and createAttributeNS() ones. You
shouldn't mix them, and, as you've seen, you can't set a prefix or a
namespace on an element or attribute create with createElement() or
createAttribute().
Dave