|
Hi,
I'm trying to use this XML parser to write new data to xml file, but have some problems, can you please send me a short code example of how to write data to a fresh clean xml file ??? I would eally appreciate this help...
Regards,
Oren
|
|
|
|
|
CXmlDocumentWrapper doc;
doc.LoadXML("<root></root>");
CXmlNodeWrapper root(doc.AsNode());
CXmlNodeWrapper node(root.InsertNode(-1,"NewNode"));
node.SetValue("SomeValue","bla bla bla");
doc.Save("C:\\somefile.xml");
Hope it works for you.
תהנה!
Creative minds - create creative creations!
|
|
|
|
|
Thanks a lot, I already managed to do it...
Great work!
Oren.
|
|
|
|
|
Fantastic Work.
I did get worried at one point that there were memory leaks within your code but when I utilised it in the way you describe in this article I have found no problems. I have also been surprised by the speed that it can read / write data. For a beginner to XML but an old hand at C++ you have certainly made life a lot easier and have brought some very large legacy data files into a new XML format.
|
|
|
|
|
m_xmldoc always = NULL even after adding the function CoInitialize(NULL).
How can I have more detail about the problem?
No error code return, only NULL value.
Many thanks
|
|
|
|
|
I found a solution: I added the CoInitialize(NULL) just before the line:
m_xmldoc.CreateInstance(MSXML2::CLSID_DOMDocument);
into the file XmlNodeWrapper.cpp
It solve the problem but maybe not the best solution. Any idea about the place to set the command CoInitialize?
Regards
|
|
|
|
|
the best way is do it at program level
void main()
{
::CoInitialize(NULL);
{
Include all COM logic within this scope
This will prevent exceptions from CoUninitialize
when COM variables are released.
}
::CoUninitialize();
}
regards
Sriram Chitturi
|
|
|
|
|
Needs to be called for each thread, not each object. Also, make sure that each CoInitialize is balanced with a CoUninitialize.
|
|
|
|
|
m_xmldoc always = NULL,because you put the function----CoInitialize(NULL) a wrong space.
you use the class in dialog framework.you want use the class in xxxDlg,you must put CoInitialize(NULL) before create DLG.
for example,
BOOL CMyApp::InitInstance()
{
CoInitialize(NULL); ---------Right method
CMyDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
}
BOOL CMyApp::InitInstance()
{
CMyDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
CoInitialize(NULL); ---------error method
}
|
|
|
|
|
Hi Alex,
I tried to use your function into a simple dialog base program.
no problem to compile but after loading the xml file, nothing is displayed into the treeview. I tried to reproduce your demo program but when I check the value of the variable m_xmlDoc, the m_xmldoc is still to 0x00000000.
Any idea to solve my issue?
1) new project (dialog based)
2) #include "XmlNodeWrapper.h"
3) added lines
CXmlDocumentWrapper doc;
doc.LoadXML("<root><someobject>");
4) compile OK
5) execution using debug mode: doc.m_xmldoc = 0x00000000.
When I execute the sample code (XMLView), m_xmldoc is different from 0x00.
Any Idea?
Thanks for your help.
Best regards,
Jmi
-- modified at 3:05 Tuesday 10th April, 2007
|
|
|
|
|
Have you forgot to call :
CoInitialize(NULL);
???
Creative minds - create creative creations!
|
|
|
|
|
You're right, I forgot to call CoInitialize(NULL);
Thanks for you support. It's working fine.
|
|
|
|
|
Great Class
support the cyrillic character set (DOS codepage 866)?? thanks
|
|
|
|
|
Fantastic work!!!!
Thanks a lot!
Pity its stuck with Microsoft.
Does anybody know one like this for xerces??
|
|
|
|
|
for( int i=0; i < node.NumAttributes(); i++ )
{
CString name = node.GetAttribname(i);
CString value = node.GetAttribValue(i);
// Edit New Value
value = ...
// Edit
node.SetValue( name, value )
}
when I use this code.
It missed " node.GetAttribname(i); ".
It returns wrong value!!( It returns next Attribute Name & Value )
Maybe SetValue Function moves Attribute Pointer.
How can I get correct Attrib?
Good Cording
|
|
|
|
|
hi, thanks for that great work, but I want to load the xml file from a url, I tried the way which explained in some message but it didnt work,
I tried this way,
doc.Load("http://www.w3schools.com/xml/note.xml");
it didn't work, can you help me?
|
|
|
|
|
i found a way to load the xml from a url, thanks for that work.
|
|
|
|
|
Hi!
I've got a problem. I have a program which uses the XMLNodeWrapper. In my program I load a XML-File in a Tree. Then I can edit my entries. In the next step I want to store my changes to a new XML-File. But how do I get the changes? How can iterate my tree to get all entries?
Thanks a lot ...
Merlin
|
|
|
|
|
Which tree are you using? Is it a CTreeView? Or you custom control , or anything else?
If you want someone to help you you should be much more specific...
Also I did not quite understand the nature of your problem: do you have a problem to read the data from the tree , or to store the new data in an existing XML structure?
Creative minds - create creative creations!
|
|
|
|
|
Thanks for your answer an sorry for beeing not specific enough. I'm a beginner an I do my first steps in programming C++.
I'm using a CTreeCtrl. I can parse my xml file and then I can show it in my CTreeCtrl. I'm also able to edit my entries. For that I'm using the CanEditLabel. After editing my entries I want to save the whole tree again in a xml-file with all the changes. But how do I get all nodes and data from the tree? This is my problem.
I hope I explained it exactly (with my bad english)
Thanks ...
Merlin
|
|
|
|
|
Hi,
I want to use a XML file by specifying its network path.
How can i use it in the m_xml.Load(filename) function
Plz help me out.
Roy
|
|
|
|
|
Load("\\ServerName\ShareName\file.xml");
or if it is a URL :
Load("http://www.someserver.com/files/file.xml");
Creative minds - create creative creations!
|
|
|
|
|
Hi,
I want to use a XML file from specifying its network path.
How can i use it in the m_xml.Load(filename) function
Plz help me out.
Roy
|
|
|
|
|
In CXmlDocumentWrapper::Load(LPCTSTR path), I see that you use _variant_t v(path) and pass v to the m_xmldoc->load(v)
But in CXmlDocumentWrapper::LoadXML(LPCTSTR xml), you call m_xmldoc->loadXML(xml) directly.
Could this cause a memory leak?
|
|
|
|
|
Header:
CXmlDocumentWrapper m_xmlDoc ;
cpp:
CString CMainFrame::TestMem()
{
CString cs = _T("<confirmSession> </confirmSession>");
m_xmlDoc.LoadXML(cs);
CXmlNodeWrapper node(m_xmlDoc.AsNode());
node.SetValue(_T("transmissionTime") , _T("protocolVersion") );
CXmlNodeWrapper Node1 ( node .InsertNode(0,_T("protocolVersion") ) );
Node1.SetValue(_T("major") ,_T("1") );
Node1.SetValue(_T("minor") ,_T("0") );
CXmlNodeWrapper Node2 ( node .InsertNode(1,_T("server") ));
Node2.SetValue(_T("type") ,_T("DLS4000") );
Node2.SetValue(_T("test1") ,_T("test1") );
Node2.SetValue(_T("clientInstanceId") ,_T("ATS DLS4000") );
m_xmlDoc.LoadXML(node.GetXML());
return m_xmlDoc.GetXML();
}
This function increases the used Memory of the Program ( NO Memory Leak )
Where is my mistake ????
2. ND PRoblem: HANDELS
CString CMainFrame::TestMem()
{
CXmlDocumentWrapper* pxmlDoc = new CXmlDocumentWrapper;
CString cs = _T("<confirmSession> </confirmSession>");
pxmlDoc->LoadXML(cs);
CXmlNodeWrapper node(pxmlDoc->AsNode());
node.SetValue(_T("transmissionTime") , _T("protocolVersion") );
CXmlNodeWrapper Node1 ( node .InsertNode(0,_T("protocolVersion")) );
Node1.SetValue(_T("major") ,_T("1") );
Node1.SetValue(_T("minor") ,_T("0") );
CXmlNodeWrapper Node2 ( node .InsertNode(1,_T("server") ) );
Node2.SetValue(_T("type") ,_T("DLS4000") );
Node2.SetValue(_T("test1") ,_T("test1") );
pxmlDoc->LoadXML(node.GetXML());
CString csRet = pxmlDoc->GetXML();
delete pxmlDoc;
pxmlDoc = NULL;
return csRet;
}
No Memory Advantage, but here are unused Handels for every Funcion Call !!
|
|
|
|