|
|
Comments and Discussions
|
|
 |

|
Ofer,
I am attempting to compile with UNICODE support and it is failing. Could you give me the details on your changes? Apparently, I don't understand your changes.
Thanks,
Pat Harren
pjharren@sbcglobal.net
|
|
|
|

|
Pat,
I added/changed the following, hope it helps:
#ifdef _UNICODE
std::wstring charToWide(const std::string &src, std::wstring &dest)
{
dest.resize(src.size(),' ');
std::copy(src.begin(),src.end(),dest.begin());
return dest;
}
#endif
inline static bool load_file(const TCHAR* path,TCHAR** buffer,unsigned long* size,unsigned long tempsize = 4096)
{
if(!path || !buffer || !size) return false;
*size = 0;
*buffer = 0;
HANDLE file_handle = CreateFile(path,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(file_handle == INVALID_HANDLE_VALUE) return false;
TCHAR* temp = (TCHAR*) malloc(sizeof(char)*tempsize);
if(!temp) return false;
unsigned long read_bytes = 0;
ZeroMemory(temp,sizeof(char)*tempsize);
while(ReadFile(file_handle,(void*)temp,tempsize-1,&read_bytes,0) && read_bytes)
{
#ifdef UNICODE
//check if the string is unicode if not convert it to unicode
if (!::IsTextUnicode((void*)temp,read_bytes,NULL))
{
std::string bufStr((char*)temp,read_bytes);
std::wstring bufWstr;
charToWide(bufStr,bufWstr);
//realloc temp so it will fit the new string
free(temp);
temp = (TCHAR*) malloc(sizeof(TCHAR)*tempsize);
memcpy(temp,bufWstr.c_str(),read_bytes*sizeof(TCHAR));
read_bytes = read_bytes*sizeof(TCHAR);
}
#endif
if (strcatgrow(buffer,temp))
{
*size += read_bytes;
ZeroMemory(temp,sizeof(TCHAR)*tempsize);
}
}
CloseHandle(file_handle);
free(temp);
return (*size) ? true : false;
}
#ifdef _UNICODE
std::wstring temp;
return has_name(charToWide(name,temp).c_str());
#else
return has_name(name.c_str());
#endif
|
|
|
|

|
Thank you, it works great.
|
|
|
|

|
//realloc temp so it will fit the new string
free(temp);
temp = (TCHAR*) malloc(sizeof(TCHAR)*tempsize);
memcpy(temp,bufWstr.c_str(),read_bytes*sizeof(TCHAR));
read_bytes = read_bytes*sizeof(TCHAR);
Don't you think there should be a handling for zero terminating strings. Elsewise wcslen of strcatgrow will fail stochastically. I've solved it through a "ZeroMemory(temp, sizeof(TCHAR)*tempsize".
Best regards, Lela
|
|
|
|

|
This question has never been answered since asked sometimes ago..
Where is the CPugXml* class implementation/headers?
It is on purpose that the class is removed from the posted header file because of commercial issue?
|
|
|
|

|
Hello,
The documentation was made by the author. In the first release, the class name are "MFC like". After some remarks, he modifiy the class name to "STL like", but he didn't modify the documentation.
You must use the doc as principle, but not as full reference documentation.
Serge
|
|
|
|

|
I get what you mean. Thanks.
|
|
|
|

|
----------------------------------
xml segment1:
...
<tag_a>
the data
<tag_b attr="aaa">other</tag_b>
</tag_a>
...
--------------------------------
xml segment2:
...
<tag_a>
<tag_b attr="aaa">other</tag_b>
the data
</tag_a>
...
--------------------------------
I can get tag_a 's value("the data") in xml segment1, bug I can't get it in xml segment2. Sorry for my English. Thanks!
|
|
|
|

|
For segment2, the value may be found as segment2.child(0).child(1).value(); note that segment2.child(0).child(1).type() is node_pcdata.
But there is a more serious problem with parsing segment2 or similar nodes: consider
<segment3>
<tag_a>
<tag_b attr="aaa" />
the data
</tag_a>
</segment3>
Here the parser "eats up" the data completely!
|
|
|
|

|
For segment2, the value may be found as segment2.child(0).child(1).value(); note that segment2.child(0).child(1).type() is node_pcdata.
But there is a more serious problem with parsing segment2 or similar nodes: consider<segment3>
<tag_a>
<tag_b attr="aaa"/>
the data
</tag_a>
</segment3>Where the node tag_bis closing itself. Here the parser "eats up" the data completely!
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Discussion of techniques for fast, robust, light-weight XML parsing.
| Type | Article |
| Licence | |
| First Posted | 11 Jan 2003 |
| Views | 693,557 |
| Bookmarked | 277 times |
|
|