You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Mark <sp...@mms.com.au> on 2007/09/26 06:32:50 UTC

XMLCh* string comparison

I've just started using Xerces and I'm using SAX2XMLReader to parse a ~250MB xml 
file. In the startElement function of my content handler I need to compare 
localname e.g. if (localname == "something"). I know I can't use == but I can't 
figure out what to use. Can anyone point me in the right direction?

TIA


Re: XMLCh* string comparison

Posted by Mark <sp...@mms.com.au>.
David Bertoni wrote:
> This is probably the most-asked question on the list, so you can search 
> the archives for XMLString::transcode() to find lots of information.

I did check but I only found 1 match and it wasn't much help. Not sure if the 
gmane search is working properly.

> 
> The most efficient thing to do is to construct static strings at compile 
> time, if you can.  Take a look at the constants in 
> src/xercesc/util/XMLUni.cpp for some examples.
> 
> The next most efficient thing to do, if you will only know the set of 
> strings you're looking for at run-time, is to use a local code page 
> transcoder to convert your strings from the local code page to UTF-16 
> strings.  For that, you can use one of the overloads of 
> XMLString::transcode(). Once you've done that, you can use 
> XMLString::equals().

Thanks I'll check it out.

Mark


Re: XMLCh* string comparison

Posted by David Bertoni <db...@apache.org>.
Mark wrote:
> I've just started using Xerces and I'm using SAX2XMLReader to parse a 
> ~250MB xml file. In the startElement function of my content handler I 
> need to compare localname e.g. if (localname == "something"). I know I 
> can't use == but I can't figure out what to use. Can anyone point me in 
> the right direction?
This is probably the most-asked question on the list, so you can search the 
archives for XMLString::transcode() to find lots of information.

The most efficient thing to do is to construct static strings at compile 
time, if you can.  Take a look at the constants in 
src/xercesc/util/XMLUni.cpp for some examples.

The next most efficient thing to do, if you will only know the set of 
strings you're looking for at run-time, is to use a local code page 
transcoder to convert your strings from the local code page to UTF-16 
strings.  For that, you can use one of the overloads of 
XMLString::transcode(). Once you've done that, you can use XMLString::equals().

Dave