Read and Write to XML file using VC++
-
I noticed myself yesterday and thought about a
CodeProject
bug since it is an unbelievable: the article had about22000
views and no vote.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
There is a
save
method for theIXMLDOMDocument
. so can add nodes to the XML file using theappendChild
function and when you are done adding all the nodes and sub nodes, you can call thesave
function, which will flush the content of theIXMLDOMDocument
to the specified file in the XML format.Now Ive Created an Xml file..... By Adding new item(.xml) in project settings... Ive started with a dialog box.... on pressing ok..the file is opened... The CODE IS: void CXMLDOMFromVCDlg::OnBnClickedEnter() { XmlDocument *docXML = new XmlDocument; docXML->LoadXml(S""); } Ive Also added : #import <msxml.dll> named_guids using namespace MSXML; .................. in stdafx.h im doing this using MFC AppWizard..... this is not working...... im getting so many ERROR: : 'XmlDocument' : undeclared identifier : 'docXML' : undeclared identifier : syntax error : identifier 'XmlDocument' : left of '->LoadXml' must point to class/struct/union : managed targeted code requires '#using <mscorlib.dll>' and '/clr' option
-
You have to use the XML DOM to read/write the XML using the vc++. See the article Introduction to Using the XML DOM from Visual C++[^]
Also can u send me some sample code... to create XML File.... and Enter data to it
-
I even tried another browser to check whether it is a bug or not... Any way it shows two votes now :)
I was just wondering who were the two 5 voters :rolleyes: :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Now Ive Created an Xml file..... By Adding new item(.xml) in project settings... Ive started with a dialog box.... on pressing ok..the file is opened... The CODE IS: void CXMLDOMFromVCDlg::OnBnClickedEnter() { XmlDocument *docXML = new XmlDocument; docXML->LoadXml(S""); } Ive Also added : #import <msxml.dll> named_guids using namespace MSXML; .................. in stdafx.h im doing this using MFC AppWizard..... this is not working...... im getting so many ERROR: : 'XmlDocument' : undeclared identifier : 'docXML' : undeclared identifier : syntax error : identifier 'XmlDocument' : left of '->LoadXml' must point to class/struct/union : managed targeted code requires '#using <mscorlib.dll>' and '/clr' option
anna mathew wrote:
XmlDocument *docXML = new XmlDocument;
no no. There is nothing called XmlDocument, it is IXMLDOMDocument. Please read the article I suggested...
anna mathew wrote:
By Adding new item(.xml) in project settings...
you add xml to project settings?? why? :confused:
-
I was just wondering who were the two 5 voters :rolleyes: :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
anna mathew wrote:
XmlDocument *docXML = new XmlDocument;
no no. There is nothing called XmlDocument, it is IXMLDOMDocument. Please read the article I suggested...
anna mathew wrote:
By Adding new item(.xml) in project settings...
you add xml to project settings?? why? :confused:
Instead of creating an XML file by coding... i tried to create it using AppWizard...thatz all ............ I made the changes u said.... void CXMLDOMFromVCDlg::OnBnClickedEnter() { IXMLDOMDocument *docXML = new IXMLDOMDocument; docXML->loadXML(S""); } but i get the following ERRORS...... ERROR: 'IXMLDOMDocument' : cannot instantiate abstract class ERROR: managed targeted code requires '#using <mscorlib.dll>' and '/clr' option Y is it????? **************************************************** I also tried::::::::: void CXMLDOMFromVCDlg::OnBnClickedEnter() { IXMLDOMDocumentPtr docPtr; docPtr.loadXML("XMLDOMFromVC.xml"); } but i get similar errors.....
-
Instead of creating an XML file by coding... i tried to create it using AppWizard...thatz all ............ I made the changes u said.... void CXMLDOMFromVCDlg::OnBnClickedEnter() { IXMLDOMDocument *docXML = new IXMLDOMDocument; docXML->loadXML(S""); } but i get the following ERRORS...... ERROR: 'IXMLDOMDocument' : cannot instantiate abstract class ERROR: managed targeted code requires '#using <mscorlib.dll>' and '/clr' option Y is it????? **************************************************** I also tried::::::::: void CXMLDOMFromVCDlg::OnBnClickedEnter() { IXMLDOMDocumentPtr docPtr; docPtr.loadXML("XMLDOMFromVC.xml"); } but i get similar errors.....
anna mathew wrote:
Instead of creating an XML file by coding... i tried to create it using AppWizard...thatz all
I dont know how you generate this codes, using App wizards. :confused: Any way this is the code for creating the IXMLDOMDocument.
IXMLDOMDocument* pXMLDoc = 0;
HRESULT hr = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, (void**)&pXMLDoc);Please understand that this is COM. You cannot simply allocate a com pointer using the
new
. -
I think the same: welcome Naveen [^]. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I think the same: welcome Naveen [^]. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]