xerces problem

Started by
3 comments, last by lincsimp 18 years, 7 months ago
hi I've just started using xerces with c++. How can I output the xmlch? const XMLCh* value=root->getNodeValue(); cout<<"["<<value<<"]"<<endl; This just ouptuts [00000000] How can i output the node value? cheeers
Advertisement
XMLCh is probably a 16-bit char (it is with my setup). I don't know if you can compile it to use something else like UTF-8 but if you could that would be awsome. Anyway to answer your question I have a class

class w2n{public:	w2n( const wstring::value_type *ptr )	{		for ( ; *ptr; ++ptr )		{			_str += *ptr & 0xff;		}	}	operator string() const	{		return _str;	}	operator const char *() const	{		return _str.c_str();	}private:	string _str;};


and then I call the constructor:

w2n( label );


Lots of ways of getting the same result of course... also this is probably not the fastest or even the correct way of moving from 16-bit to 8-bit characters.
Thanks!
I have this:


const XMLCh* value=root->getNodeValue();
cout<<w2n(value)<<endl;

I got an error:

Unhandled exception at 0x00418755 in LanguageConverter.exe: 0xC0000005: Access violation reading location 0x00000000.

at this line:

for ( ; *ptr; ++ptr )

whats wrong?

Quote:Original post by lincsimp
Thanks!
I have this:


const XMLCh* value=root->getNodeValue();
cout<<w2n(value)<<endl;

I got an error:

Unhandled exception at 0x00418755 in LanguageConverter.exe: 0xC0000005: Access violation reading location 0x00000000.

at this line:

for ( ; *ptr; ++ptr )

whats wrong?


maybe getNodeValue() is returning null? In fact I would guess that's why its outputing 00000000 because the pointer is null... Since cout doesn't have a method for short*, it just uses the default for void* and prints the address.
Thanks, I don't see why it would return null, here's the code:


XMLCh tempStr[100];

XMLString::transcode("Range", tempStr, 99);
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(tempStr);

XMLString::transcode("root", tempStr, 99);
DOMDocument* doc = impl->createDocument(0, tempStr, 0);
DOMElement* root = doc->getDocumentElement();

XMLString::transcode("FirstElement", tempStr, 99);
DOMElement* e1 = doc->createElement(tempStr);
root->appendChild(e1);

XMLString::transcode("SecondElement", tempStr, 99);
DOMElement* e2 = doc->createElement(tempStr);
root->appendChild(e2);

XMLString::transcode("aTextNode", tempStr, 99);
DOMText* textNode = doc->createTextNode(tempStr);
e1->appendChild(textNode);

// optionally, call release() to release the resource associated with the range after done
DOMRange* range = doc->createRange();
range->release();

// removedElement is an orphaned node, optionally call release() to release associated resource
DOMNode* removedElement = root->removeChild(e2);
removedElement->release();

// no need to release this returned object which is owned by implementation
XMLString::transcode("*", tempStr, 99);
DOMNodeList* nodeList = doc->getElementsByTagName(tempStr);
//DOMNode* test = (DOMNode)root;

const XMLCh* value=root->getNodeValue();
cout<<w2n(value)<<endl;



can anyone give some guidance????

cheers

This topic is closed to new replies.

Advertisement