|
I don't see any sort of license attached to the article or downloaded source. Does this mean that you have released the code as Public Domain?
I need to know the "official" license state so I can determine if this code could be used in my product. It would sure save me a lot of headache if I could, but need to know that any code I use is not infringing.
Thank you.
|
|
|
|
|
Appropriate license was applied... Bug fixed
Thing is, that the article was published before CP imlemented thier licensing policies so it was not updated.
Thanks for bringing this to my attention.
Creative minds - create creative creations!
|
|
|
|
|
Hi.
I need to create this piece of code,
<br />
<SessionsList><br />
<Session ID="2" FrameID="1"><br />
</Session><br />
</SessionsList><br />
How can I do that??
I tried:
<br />
CXmlNodeWrapper Session(pNextSessionNode=pXmlNodeWrapper.InsertNode(0, "Session"));<br />
sprintf(szXmlStr, "ID=%c0x%02X%c FrameID=%c0x%02X%c", '"', pSessionData->GetSessionID(), '"', '"', pSessionData->GetUniqueID(), '"');<br />
Session.SetText(szXmlStr);<br />
it doesn't work...any ideas ??
Thanks.
Oren.
|
|
|
|
|
node.SetValue("ID", szID);
node.SetValue("FrameID", szFrameID);
Creative minds - create creative creations!
|
|
|
|
|
Hi.
I have this piece of XML:
<br />
<SessionsList><br />
<Session ID="2" FrameID="1"><br />
<MessageType>0x2B</MessageType><br />
< Params><br />
<BMRID>0x01</BMRID><br />
<SessionID>0x02</SessionID><br />
<FrameID>0x01</FrameID><br />
</Params> <br />
</Session><br />
</SessionsList><br />
My question is, How can I use the 'FindNodes()' to find me all 'Sessions' where ID=2 AND FrameID=1 ???
I tried:
node.FindNodes("//Session[@ID='2' FrameID='1']")
node.FindNodes("//Session[@ID='2' @FrameID='1']")
node.FindNodes("//Session[@ID='2' & FrameID='1']")
none of them works, but if I write
node.FindNodes("//Session[@ID='2']")
it doesn work, but I need it to find all nodes with 2 conditions and not 1.
Thanks.
Oren
-- modified at 2:54 Tuesday 23rd October, 2007
|
|
|
|
|
Hi, you should use: node.FindNodes("//Session[@ID='2' and @FrameID='1']")
Creative minds - create creative creations!
|
|
|
|
|
Hi All,
Thanks for this great article, I'd really like to be able to use this method to work with XML, but i'm having trouble compiling.
The example download compiles fine, but if I follow the steps:
- add XmlNodeWrapper.cpp file, then #include the header
I get compilation errors
Here are the first 3 errors:
error C2440: 'default argument' : cannot convert from 'const char [1]' to 'LPCTSTR' ..\XmlNodeWrapper.h (line)72
error C2548: 'CXmlDocumentWrapper::Save' : missing default parameter for parameter 1 ...\XmlNodeWrapper.h (line)72
error C2039: 'Getattributes' : is not a member of 'MSXML2::IXMLDOMNode' ...\XmlNodeWrapper.cpp (line)46
Any ideas where i'm going wrong? is there some other setting I've missed?
Thanks!
|
|
|
|
|
|
Uou must be using some different unicode settings...
Try playing with those.
Creative minds - create creative creations!
|
|
|
|
|
Dear,
I get success at creating the ProcessingInstruction as below:
IXMLDOMElementPtr spElementRoot = m_xmldoc->createElement("Root");
m_xmldoc->documentElement = spElementRoot;
xmldoc->insertBefore((IXMLDOMNode*)m_xmldoc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), _variant_t((LPDISPATCH)spElementRoot.GetInterfacePtr()));
But the problem is I don't know how to create this string (right below xml version = "1.0"):
Is it a ProcessingInstruction or a TextNode?
Please help!
|
|
|
|
|
Answered by myself:
Is it a ProcessingInstruction or a TextNode?
It is a comment, and to insert it right below the processing instruction call insertBefore like this:
xmldoc->insertBefore((IXMLDOMNode*)m_xmldoc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), _variant_t((LPDISPATCH)spElementRoot.GetInterfacePtr()));
xmldoc->insertBefore(m_xmldoc->createComment(__bstr_t("Generated by Alex Hazanov"), _variant_t((LPDISPATCH)spElementRoot.GetInterfacePtr()));
Thank you all!
|
|
|
|
|
MSXML2::IXMLDOMNode* CXmlNodeWrapper::FindNode(LPCTSTR searchString)
So many thanks but when I try to use FindNode method, I get fail.
For example, I had built this xml doc:
<code>
<Box ID="box_id2" Path="C:\">
<File FileName="artpdbg.log" />
<File FileName="GHOST.EXE" />
</Box>
</code>
But when I called root.FindNode("//Box[@ID='box_id2']") I got a NULL pointer.
Please help!
|
|
|
|
|
It must be my fault. I works now. Thanks
|
|
|
|
|
Dear Alex,
I have a trouble using your XML wrapper
I have to remove all the items contained in a section of xml files (both nodes and values). The RemoveNodes member allow to remove the nodes .... but .... how the remove all the values contained in a branch?
Thank You
Furno G.Luca
------------------------------------------------------------
Furno G.Luca
MicroSHADOW Research (uS)
Development dept.
Via Garibaldi, 25
19020 Ceparana (SP) - ITALY
Tel : +39(0187)940951
Fax: +39(199)449896
Mobile : 3337665111
e-mail: info@microshadow.com
web: http://www.microshadow.com
------------------------------------------------------------
|
|
|
|
|
Basically when you remove a node , you remove all the values and child nodes that it has... so I am not sure I understand your question... A small example would help.
Creative minds - create creative creations!
|
|
|
|
|
Thank you for your answer Alex.
Basically i want to remove all the entries contained in a node without remove the node itself. For example:
If i have
//root//mysection//
and under <mysection> i have several entries (string values and other child nodes). What i want to do is to clean-up the entire content of <mysection> without remove it.
I can say ... if we were in DOS i would like to have the same result of ...
cd \root\mysection
del *.*
Hope it is quite clear
Thank you for yor time
gLuca
|
|
|
|
|
RemoveNodes uses XPath to find the nodes , hence you should use something like :
root.RemoveNodes("//section/*");
Creative minds - create creative creations!
|
|
|
|
|
Dear Alex,
OK!
Everything Solved!
Thank u ...
Furno G.Luca
------------------------------------------------------------
Furno G.Luca
MicroSHADOW Research (uS)
Development dept.
Via Garibaldi, 25
19020 Ceparana (SP) - ITALY
Tel : +39(0187)940951
Mobile : 3337665111
e-mail: info@microshadow.com
web: http://www.microshadow.com
------------------------------------------------------------
|
|
|
|
|
Hello !
I want to use this code in another Project.
I want to create a CString with XML Data.
CString CMainFrame::TestMem()
{
CXmlDocumentWrapper xmlDoc;
CString cs = _T("<confirmsession> ");
xmlDoc.LoadXML(cs);
CXmlNodeWrapper node(xmlDoc.AsNode() );<br />
node.SetValue(_T("test") , _T("protocolVersion") );
CString csRet=_T("");// = m_xmlDoc.GetXML();
return csRet;
}
The red code causes the Problem, where is the mistake ???
How do i have to delete the CXmlNodeWrapper node object ??
Thanks !!!
|
|
|
|
|
As you can see the post engine probably stripped the xml tags in the CString cs = ...
line so I don't know what is it that you are trying to load, is it a valid xml?
Creative minds - create creative creations!
|
|
|
|
|
I don`t want to load xml, i want to generate valid xml !!!
|
|
|
|
|
Well you have to start somewhere. Untill the XmlDocument object is loaded with some valid xml it is empty and not valid and of course has no nodes so that "AsNode" function will return nothing and the "SetValue" function is performed on an empty node!
I would suggest:
CString CMainFrame::TestMem()
{
CXmlDocumentWrapper xmlDoc;
CString cs = _T("<Root></Root>");
xmlDoc.LoadXML(cs);
CXmlNodeWrapper node(xmlDoc.AsNode() );
node.SetValue(_T("test") , _T("protocolVersion") );
CString csRet = m_xmlDoc.GetXML();
return csRet;
}
This way the returned string would be:
<Root test="protocolVersion"/>
Creative minds - create creative creations!
|
|
|
|
|
Oh... and you don't have to delete the object it's self destructive... so there is no memory leaks.
Creative minds - create creative creations!
|
|
|
|
|
Hello Alex, Thanks for your endeavours!
I changed the code to:
CString CMainFrame::TestMem()
{
CXmlDocumentWrapper xmlDoc;
CString cs = _T("<Root></Root>");
xmlDoc.LoadXML(cs);
CXmlNodeWrapper node(xmlDoc.AsNode() );
node.SetValue(_T("test") , _T("protocolVersion") );
CString csRet= xmlDoc.GetXML();
return csRet;
}
The result is the desired result :<Root test="protocolVersion"></Root>
But the memory problem still exists !!!
|
|
|
|
|
I had the same memory problem with the code. Modifying the classes, adding copy constructors and re-writing the assignment operators helped. The copy constructors need to be provided as the compiler supplied ones obviously leak memory. See examples below.
Constructors:
CSKXmlNode::CSKXmlNode( const CSKXmlNode &objNode )
:
m_xmlnode ( MSXML2::IXMLDOMNodePtr( objNode.m_xmlnode ) ),
m_nodeNum ( objNode.m_nodeNum )
{
}
CSKXmlNode::CSKXmlNode( MSXML2::IXMLDOMNodePtr &objNodePtr )
:
m_xmlnode ( MSXML2::IXMLDOMNodePtr( objNodePtr ) ),
m_nodeNum ( 0 )
{
} (I removed m_bAutoRelease member variable from the class)
Assignment operator:
CSKXmlNode& CSKXmlNode::operator=( const CSKXmlNode &objNode )
{
if ( this != &objNode )
{
m_nodeNum = objNode.m_nodeNum;
if( m_xmlnode )
{
m_xmlnode.Release( );
}
m_xmlnode = MSXML2::IXMLDOMNodePtr( objNode.m_xmlnode );
}
return *this;
}
Otherwise very helpful wrapper. Thanks Alex!
|
|
|
|