|
You are using unicode strings, I guess.
There is another possible problem around the memcpy:
GetBufferSetLength() doesn't work with a terminating '\0'. So instead of having
LPTSTR pss = ps->GetBufferSetLength(len + 1 );
memcpy( pss, psz, len );
pss[len] = '\0';
This code would be more appropriate:
LPTSTR pss = ps->GetBufferSetLength(len);
memcpy( pss, psz, len );
The same in _tagXMLEntitys::Ref2Entity()( LPCTSTR str ):
LPTSTR esbuf = es.GetBufferSetLength( len );
and in _tagXMLEntitys::Entity2Ref( LPCTSTR str ):
LPTSTR sbuf = s.GetBufferSetLength( len );
means in _tagXMLEntitys::Entity2Ref( LPCTSTR str, LPTSTR estr, int estrlen ) the string terminater cannot be set anymore:
as well as in _tagXMLEntitys::Ref2Entity( LPCTSTR estr, LPTSTR str, int strlen ):
I can't think of a case when this could really make a difference, it's probably mere code sanitizing. But ever since I moved from VS6 to VS2008 I encountered strange crashes where CSimpleStringT is involved quite often. Maybe the new ATL string manager used in VC9 isn't as tolerant as the one in VC6...
|
|
|
|
|
when my xml like this
<?xml version="1.0" encoding="gb2312" ?>
<ListItem11>
<BookId>36027</BookId>
<CalledName>\\;</CalledName>
</ListItem11>
there got problems,thank you!
ww
-- modified at 1:22 Sunday 30th April, 2006
|
|
|
|
|
if you want get PI node (<?xml?>), then you must use XDoc, not XNode.
and XMLite's default escape character is '\'. and you can disable it.
here is answer.
void CTestXMLiteDlg::OnButton15()
{
// TODO: Add your control notification handler code here
CString sXML = "\
<?xml version=\"1.0\" encoding=\"gb2312\" ?>\
<ListItem11>\
<BookId>36027</BookId>\
<CalledName>\\\\;</CalledName>\
</ListItem11>\
";
XDoc node;
PARSEINFO piNoescape;
piNoescape.escape_value = 0;
if( node.Load( sXML, &piNoescape ) )
{
AfxMessageBox( node.GetXML() );
}
}
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
The following function will crash if called a second time, why?
void foo::foo()
{
XNode xml_lnk;
LPXNode link_node;
xml_lnk.name = "LINK_INFO";
link_node = xml_lnk.CreateNode("LINK","S GOYER RD ");
link_node->AppendAttr("id","0x08d3befa");
xml_lnk.AppendChild(link_node);
link_node = xml_lnk.CreateNode("LINK","E SOUTHWAY BLVD");
link_node->AppendAttr("id","0x08d3bef7");
xml_lnk.AppendChild(link_node);
XNode xml_ri;
xml_ri.name = "ROUTE_INFO";
xml_ri.AppendChild("ROUTE_INFO_ID","2");
xml_ri.AppendChild(&xml_lnk); //this crashes second foo is called
MessageBox(xml_ri.GetXML());
}
|
|
|
|
|
XNode object's destructor will be delete all child nodes.
xml_lnk is child of xml_ri.
so xml_ri's Close() try to delete xml_lnk object.
but it's illigal.
you have to use one XNode or use CopyNode() or CopyBranch().
-- modified at 19:44 Tuesday 7th November, 2006
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Compiler retruns 7 errors like this.
.\XMLite.cpp(853) : error C2664: 'std::_Vector_iterator<_Ty,_Alloc>::_Vector_iterator(const std::_Vector_iterator<_Ty,_Alloc> &)' : cannot convert parameter 1 from 'int' to 'const std::_Vector_iterator<_Ty,_Alloc> &'
with
[
_Ty=LPXNode ,
_Alloc=std::allocator<LPXNode >
]
Reason: cannot convert from 'int' to 'const std::_Vector_iterator<_Ty,_Alloc>'
with
[
_Ty=LPXNode ,
_Alloc=std::allocator<LPXNode >
]
No constructor could take the source type, or constructor overload resolution was ambiguous
for this member function
<code>XNodes::iterator _tagXMLNode::GetChildIterator( LPXNode node )
{
XNodes::iterator it = childs.begin();
for( ; it != childs.end() ; ++(it) )
{
if( *it == node )
return it;
}
return NULL;
}</code>
Problem is that you cannot return NULL.
Is it correct when I change return NULL with return childs.end() ?
Palo
|
|
|
|
|
yes. it's my fault.
thanks for fix.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
|
Hi, youbang zhang.
Thank you for your unicode version.
I will check it up and update info on xmlite page.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Where can I download unicode version of source code?
Specified link isn't yet valid.
Cho, Kyung-min, it will be hopeful add (publish) it on this page.
Thank you.
|
|
|
|
|
Hi Cho, Kyung-min,
Does the parser cope with multiple branches?
I tried the following XML in your examples, but only the first branch (AddressBook) seemed to be accessible:-
sxml = _T("<addressbook description="\"book" of="" bro\"="">\
<person type="me"><name>Cho,Kyung Min<nick>bro\
<person type="friend"><name>Baik,Ji Hoon<nick>bjh\
<person type="friend"><name>Bak,Gun Joo<nick>dichter\
<information count="3">\
\
<personaldirectory description="\"book" of="" friends\"="">\
<person type="me"><name>Clark,Peter<nick>Pete\
<person type="friend"><name>Ridler,Kevin<nick>Kev\
<person type="friend"><name>Hermes,Bernard<nick>Berni\
<information count="3">\
");
Should it be possible to access to the PersonalDirectory XML section ?
Many thanks,
Peter Clark
peterashleyclark@yahoo.co.uk
|
|
|
|
|
Hi, picnic.
XMLite process one root element.
in branch copy (deep-copy) section, that code is wrong on this page. (problem with html tag processing)
but source example code is works.
and if you want to multiple root elements, I wrote already about it before.
-------------------
XNode in XMLite can parse one element.
so, xnode.Load( "<a></a><b></b><c></c>" ) , then xnode parse only .
if you want to parse all elements, then write below
( somebody ask to me how to do this )
CString s;
s = _T("<a></a><b></b><c></c>");
XNode a,b,c;
LPTSTR pa = (LPTSTR)(LPCTSTR)s;
LPTSTR pb = a.Load( pa );
LPTSTR pc = b.Load( pb );
LPTSTR pNull = c.Load( pc );
TRACE(_T("%s %s %s"), a.name , b.name, c.name );
<h6>Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.</h6>
-- modified at 21:04 Wednesday 25th January, 2006
|
|
|
|
|
Hi,
I am working on my thesis that about doing a server application for a company.
thay have a Messenger (it's name is Cute Messenger) and thay want me to do a server application so it can do it possible to members of Cute Messenger that chat with thier friends on MSN messenger or ICQ or Yahoo messenger.
I am a newbie and I have hort that it can be possible by Jabber, I saw your aricle and i thought you maybe can help me and give some advice or tip.
you can write to me dirctly to my mail: arash22@hotmail.com
thank you so much.
and sorry about my bad english
arash
|
|
|
|
|
I worked with jabber server as you see on my introduction page, I choose win32 jaber com client library, but at that time, jabercom doesn't support korean language.
so i make own jaber client program. XMLite is a by-product in that project.
jabber.org shows how can talk with jabber server.
sorry for my poor english too.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
In fact, XMLite has almost thought about UNICODE, but we need to make a little correcting work :
1. add these code to XMLite.h
<br />
#ifdef _UNICODE<br />
typedef std::wostringstream tostringstream;<br />
#define _tmemcpy wmemcpy<br />
#else<br />
typedef std::ostringstream tostringstream;<br />
#define _tmemcpy memcpy<br />
#endif<br />
2. some changes in XMLite.cpp
(1)find all "std::ostringstream", change them to "tostringstream"
(2)in function "_SetString", find
<br />
memcpy( pss, psz, len );<br />
change "memcpy" to "_tmemcpy"
then it seems work fine, but I've not tested a lot
|
|
|
|
|
Hi, Hewllet.
Thanks for your advice.
Your share thing will be help me and others.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Hi,
You can do this much simpler.
typedef std::basic_ostringstream<tchar, std::char_traits<tchar="">, std::allocator<tchar> > tostringstream;
|
|
|
|
|
GetChildIterator may return NULL.
This may cause RemoveChild and DetachChild to run vector::erase(NULL) which is likely to produce a crash.
Feels to me like GetChildIterator should return childs.end() if the node isn't found. (Also, returning childs.end() feels a bit more "stl-like" then returning NULL).
|
|
|
|
|
|
You are nice too, duan zuoyi.
Thank you all. No one know oneself all. My idea from you, book, all others. already we are shared brains.
|
|
|
|
|
Great project, very useful.
I notice when you use GetBufferSetLength(), there is no corresponding releaseBuffer call. That is adding an extra '\0' at the end of CString and make the size of CString one bigger.
|
|
|
|
|
GetBufferSetLength() needs no ReleaseBuffer(). But you are right with the size problem. See my reply to Fernando A. Gómez' post on 15-May-06 12:54.
|
|
|
|
|
One of the reasons of XML is connecting platforms, apps through text encoded messages, to achieve this you need compliance. Implementing a fully (95%-98%) compliant XML parser is really hard. Usually an average Dev can get to 80% pretty quickly and the experienced can get to %90. The rest is all egde cases and getting them right requires extensive testing suites to ensure compat between different platforms. I know this by experience. There are quite a few xml parser implementations out there. Users are usually best served when the xml parser implementations are recognized by the W3C Recommendations. Other implementations can not go any further than academic studies as the cost of them making interop with the rest of the world sky rockets as dev's are trying to achieve %95 compat.
|
|
|
|
|
My thoughts on it:
A lot of warning C4018: '<' : signed/unsigned mismatch when compiling. Doesn't really matter but should be fixed.
Also, a couple of error C2451: conditional expression of type 'std::vector<_Ty>::iterator' is illegal
For example, in bool _tagXMLNode::RemoveChild( LPXNode node ), you do
if( it )
What's that supposed to mean? Shouldn't it be something like if( it != childs.end())?
|
|
|
|
|
I get the errors in vs.net,but successful in vs6.0;P
|
|
|
|
|