NSan wrote:
Hi there,

I'm trying for a while to obtain the XML content of a file without spaces.

I have a XML file with the following content:

...

It happens that I need to obtain the name and type values from the XML but
I'm getting the content with white spaces. Here is the code I'm trying to
use:
The XML recommendation requires the parser report all of the content of the document. If you have element-only content, then you can write a DTD that indicates that, and use validation. In that case, that whitespace is reported in the ignorableWhitespace callback, and not in the characters() callback.

Code: ( text )

...
void MySAX2Handler::characters(const XMLCh* const chars, const
unsigned int length)
      {
          char* message = XMLString::transcode(chars);
          std::cout << "Characters: " << message << " Lenght: " << length <<
std::endl;
          if (XMLString::compareIString(chars,XMLUni::fgZeroLen  String) !=
0) {
Those strings are not zero-length, so this is clearly going to fail. Also, there is not guarantee the buffer pointed to by "chars" is null-terminated, so it's dangerous to use a function that expects a null-terminated buffer.

You can use XMLChar::isAllSpaces() to determine if an event is all whitespace, but be careful, because there is no guarantee in SAX that all of the data for a particular text node will be delivered all at once. Most SAX application buffer character data until the next callback function that is not characters() gets called.

Dave

Reply via email to