|
How do I update an attribute of a node?
node.SetValue works but it places the node at then end of the file and this upsets the loop though the nodes when you try and reload the XML file
|
|
|
|
|
You would have to eleborate on the subject since I didn't get what the issue is, since SetValue usualy works for me without any problem... This just sets the attribute without changing the node or it's position...
Creative minds - create creative creations!
|
|
|
|
|
Hi Alex yes it is strange as I was using SetValue and it was changing the values fine but it would place the updated value at the end of the main tag so when the application re read the XML it would not loop though the nodes correctly as 0 or 1,2,3 and so on were no longer in order and the loop failed but I guess there is a work around for this.
|
|
|
|
|
Great article!
I have only a small suggestion (which I'll make in the version that I'll use):
Why not having GetValue functions for int, short, double etc, like the SetValue ones?
Otherwise a top notch work. I voted 6 only because there is no higher value .
Best regards,
X3m
|
|
|
|
|
Thanks alot, I appreciate the input.
Your suggestion among other usefull additions are awaiting me, finding some free time to update the article...
Alas... you should understand what it means... hopefully in near future.
Creative minds - create creative creations!
|
|
|
|
|
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!
|
|
|
|