You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Alexander Broekhuis <a....@admiraalkruys.nl> on 2004/07/20 15:24:36 UTC

LPTSTR to DOMDocument

Hi,

I have a LPTSTR and want to create a DOM Document from that string. I use
a LPTSTR for unicode chars.

At the moment I am trying to use this:
------------------------------------------------------------------------
MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
wcslen(xml), "xmlRecord", false); // In this line xml is the LPTSTR that
contains the xml.
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
DOMBuilder *parser =
((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,
0);
Wrapper4InputSource* domBufIS = NULL;
domBufIS = new Wrapper4InputSource ( memBufIS );
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = parser->parse(*domBufIS);
DOMElement * root = doc->getDocumentElement();
------------------------------------------------------------------------

This piece of code fails when it tries to parse the domBufIS and wants to
create a DOMDocument. If I debug this code the XMLByte from
MemBufInputSource seems to have only the first char from xml (a "<").

Are there better/other ways to create a DOMDocument from a LPTSTR?

TiA,

Alexander



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: LPTSTR to DOMDocument

Posted by Alberto Massari <am...@progress.com>.
At 16.02 20/07/2004 +0200, Alexander Broekhuis wrote:
>Hi,
>
> >>At the moment I am trying to use this:
> >>------------------------------------------------------------------------
> >>MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
> >>wcslen(xml), "xmlRecord", false); // In this line xml is the LPTSTR that
> >>contains the xml.
> >
> > The MemBufInputSource works on buffers of XMLByte, so the length must be
> > in
> > bytes; wcslen returns the number of wchar_t (or XMLCh, on Windows), so you
> > need to multiply it by 2. Or, to be on the safe side, you should always
> > use
> > TCHAR-based code, like this
> >
> > MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
> > _tcslen(xml)*sizeof(TCHAR), "xmlRecord", false);
> >
>
>This is an other problem then that i have, thx for the hint btw :), I
>changed that piece of code.
>The problem I have is the the XMLByte only contains the first char of xml.

No, that's just a display problem; you are looking at a piece of Unicode 
data, that is 2 character wide. When that string contains a normal ASCII 
character, the second char is 0, so if you read it as it was a normal ASCII 
string you only see the "<" string. If you are inside Visual Studio (as I 
guess, given that you deal with TCHAR types...) go to Tools | Options | 
Debug and check the "Display Unicode Strings" check box.
If you need to display the value of a variable that is not declared to be a 
LPTSTR, enter a watch expression like "xml,su" (where ",su" means "display 
as it were a Unicode string")

Alberto



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: LPTSTR to DOMDocument

Posted by Alexander Broekhuis <a....@admiraalkruys.nl>.
Hi,

>>At the moment I am trying to use this:
>>------------------------------------------------------------------------
>>MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
>>wcslen(xml), "xmlRecord", false); // In this line xml is the LPTSTR that
>>contains the xml.
>
> The MemBufInputSource works on buffers of XMLByte, so the length must be
> in
> bytes; wcslen returns the number of wchar_t (or XMLCh, on Windows), so you
> need to multiply it by 2. Or, to be on the safe side, you should always
> use
> TCHAR-based code, like this
>
> MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
> _tcslen(xml)*sizeof(TCHAR), "xmlRecord", false);
>

This is an other problem then that i have, thx for the hint btw :), I
changed that piece of code.
The problem I have is the the XMLByte only contains the first char of xml.

Alexander

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: LPTSTR to DOMDocument

Posted by Alberto Massari <am...@progress.com>.
Hi Alexander,

At 15.24 20/07/2004 +0200, Alexander Broekhuis wrote:
>Hi,
>
>I have a LPTSTR and want to create a DOM Document from that string. I use
>a LPTSTR for unicode chars.
>
>At the moment I am trying to use this:
>------------------------------------------------------------------------
>MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
>wcslen(xml), "xmlRecord", false); // In this line xml is the LPTSTR that
>contains the xml.

The MemBufInputSource works on buffers of XMLByte, so the length must be in 
bytes; wcslen returns the number of wchar_t (or XMLCh, on Windows), so you 
need to multiply it by 2. Or, to be on the safe side, you should always use 
TCHAR-based code, like this

MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)xml,
_tcslen(xml)*sizeof(TCHAR), "xmlRecord", false);

Alberto

>static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
>DOMImplementation *impl =
>DOMImplementationRegistry::getDOMImplementation(gLS);
>DOMBuilder *parser =
>((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS,
>0);
>Wrapper4InputSource* domBufIS = NULL;
>domBufIS = new Wrapper4InputSource ( memBufIS );
>XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = parser->parse(*domBufIS);
>DOMElement * root = doc->getDocumentElement();
>------------------------------------------------------------------------
>
>This piece of code fails when it tries to parse the domBufIS and wants to
>create a DOMDocument. If I debug this code the XMLByte from
>MemBufInputSource seems to have only the first char from xml (a "<").
>
>Are there better/other ways to create a DOMDocument from a LPTSTR?
>
>TiA,
>
>Alexander
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org