|
thank you, that helped a lot!
|
|
|
|
|
In this win32 code, how can I write a simple XML file like:
<?xml version="1.0"?>
<WEBSITES>
<SERVER>
<NAME>www.codeproject.com</NAME>
</SERVER>
</WEBSITES>
Am kind of new to XML and the link above only mentioned reading of XML and dumping that into a file. I wanted to create one from scratch. Help would be appreciated!
|
|
|
|
|
Great article!
I'm wonder what could be a right way to check if item name is well formed (spaces, tildas...)?
Otherwise CXmlNodeWrapper::GetValue(), CXmlNodeWrapper::SetValue(sName, sValue) might throw a com exception.
Gennady
|
|
|
|
|
I want to move up/down the node in my XML and then save this state to my file. How can I archive this?
Please help,
Many thanks!
modified on Thursday, October 7, 2010 4:01 AM
|
|
|
|
|
You library is OS-dependant
|
|
|
|
|
This is good. I have a slightly different approach that automates the transfer of the XML elements and attributes to and from member variables and data structures that contains them. The article is posted on codeproject:
XMLFoundation[^]
|
|
|
|
|
Hi guys,
This class is really awesom! Also very easy to use. Thank you, Alex.
If you want to load UTF-8 string from xml files correct, the code is needed modifying all the return (LPCSTR) to (LPCTSTR). I had been testing it for one day.
Good Luck.
|
|
|
|
|
If I try to compile the below sample code I get the error:
error C2039: 'QueryInterface' : is not a member of 'CXmlNodeWrapper'
c:\program files\microsoft visual studio 8\vc\include\comip.h 852
Sample:
CXmlDocumentWrapper doc;
if ( !doc.Load(szPath) )
{
doc.LoadXML("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<Settings Major=\"1\" Minor=\"10\" Revision=\"0\" Build=\"14\">/Settings>");
doc.Save(szPath);
}
CXmlNodeWrapper root(doc.AsNode());
CXmlNodeWrapper node;
node.SetText(_T("TestNode"));
node.SetValue(_T("AttribA"), 1);
node.SetValue(_T("AttribB"), 170);
root.InsertNode(root.NumNodes(), &node);
doc.Save(szPath);
|
|
|
|
|
I needed to serialize some objects to XML, and first tried this wrapper but it was difficult to use if wanting to get/set the text inside the xml-nodes (and not just attributes).
Instead I found that CXml - A Wrapping Class for MSXML 3.0/4.0/5.0/6.0[^] was easy to use and solved all my needs.
|
|
|
|
|
I started using this Xml parser class and so far it has been very easy to use. However, I encounter the problem of unable to open any file with fopen_s after using a temporary CXmlDocumentWrapper object to parse an incoming Xml string. The simplest way to reproduce this bug is to place a "test.txt" in a known folder, add a new button in the given project for this topic and inside the OnBtnClick message function, add the fopen_s to open a "test.txt" file:
void CDBTest2Dlg::OnBnClickedButton2()
{
FILE *FileIn;
if(fopen_s(&FileIn,"test.txt","r")==0)
{
TRACE("File is opened\n");
fclose(FileIn);
}
else
{
TRACE("File is not opened\n");
}
}
If the new button is clicked without clicking on the Open File button, the file will open successfully. However it will fail to open after opening an xml tree using Open File button. My program requires the use of both fopen_s and the Xml parser at various parts. Is there anyway to solve this problem?
|
|
|
|
|
<AUTHENTICATION>
<USER><USERNAME> TEST</USERNAME>
<PASSWORD>ABC123</PASSWORD>
<ROLE>ADMIN</ROLE>
</USER>
</AUTHENTICATION>
I have the above XML. When I use the GetText() function it does not return me the value with whitespace in front. Instead of getting " TEST", I'm getting "TEST".
How can I get the value with whitespace?
Thanks in advance.
|
|
|
|
|
Hello Alex:
I'm just to begin to learn programing.
May I ask you some questions to XMLfile's reference?
This is the file I wanna read:
<DATA-OBJECT-PROPS>
<DATA-OBJECT-PROP ID="_63" OID="DOP_38E431A637EA415e870161B54FC72EED">
<SHORT-NAME>Start_NR_DOP</SHORT-NAME>
<LONG-NAME>Start NR_DOP</LONG-NAME>
<COMPU-METHOD>
<CATEGORY>TEXTTABLE</CATEGORY>
<COMPU-INTERNAL-TO-PHYS>
<COMPU-SCALES>
<COMPU-SCALE>
<LOWER-LIMIT>18</LOWER-LIMIT>
</COMPU-SCALE>
<COMPU-SCALE>
<LOWER-LIMIT>19</LOWER-LIMIT>
</COMPU-SCALE>
<COMPU-SCALE>
<LOWER-LIMIT>34</LOWER-LIMIT>
</COMPU-SCALE>
</COMPU-SCALES>
</COMPU-INTERNAL-TO-PHYS>
</COMPU-METHOD>
</DATA-OBJECT-PROP>
<NEG-RESPONSES>
<NEG-RESPONSE ID="_129" OID="44D8146221B34917A4777344C87B425C_1238659331A8484f96D15CC28DA52B3F">
<SHORT-NAME>NR_DefaultSession_Start</SHORT-NAME>
<LONG-NAME>NR Default Session Start</LONG-NAME>
<PARAMS>
<PARAM OID="44D8146221B34917A4777344C87B425C_4F2A8A6DAC7A4affB9F34F185030E7B9" SEMANTIC="SERVICEIDRQ" xsi:type="CODED-CONST">
<SHORT-NAME>SIDRQ_NR</SHORT-NAME>
<LONG-NAME>SIDRQ-NR</LONG-NAME>
<BYTE-POSITION>1</BYTE-POSITION>
<CODED-VALUE>16</CODED-VALUE>
<DIAG-CODED-TYPE BASE-DATA-TYPE="A_UINT32" xsi:type="STANDARD-LENGTH-TYPE">
<BIT-LENGTH>8</BIT-LENGTH>
</DIAG-CODED-TYPE>
</PARAM>
<PARAM OID="4FC13B0A745F48ff84AFDE9EAFCEBED5_38E431A637EA415e870161B54FC72EED" SEMANTIC="DATA" xsi:type="VALUE">
<SHORT-NAME>Start_NR</SHORT-NAME>
<LONG-NAME>Start NR</LONG-NAME>
<BYTE-POSITION>2</BYTE-POSITION>
<DOP-REF ID-REF="_63"/>
</PARAM>
</PARAMS>
</NEG-RESPONSE>
I want to do these action:
1. Enter a value "16", then find the same value "16" in NEG-RESPONSE\PARAMS\PARAM\CODED-VALUE.
2. Find out DOP-REF ID-REF="_63" on the other PARAM node of NEG-RESPONSE.
3. Find out a DATA-OBJECT-PROP node (ID = _63).
4. Get LOWER-LIMIT value (18.19.34) of the DATA-OBJECT-PROP node (ID = _63).
How should I make the steps above?
The program I use is Microsoft Visual Studio 2005.
Thanks for reply.
|
|
|
|
|
I have an exam about use c++ to read and write xml . It is so hard and difficult for new coming as I
Thank you for the good project
|
|
|
|
|
Thank you , it works fine , but a little trouble about memory leak .
While I finished using it , I called detach or release methods to free memory , but it was not effective.
So would you please help me about this issue ?
Expecting your reply , thank you!
|
|
|
|
|
Any ideas about how to release the memory after using it? I tried many ways, but could not figure out. Please let me know if anyone has an idea for it. Thanks.
|
|
|
|
|
I encountered same memory leak issue. anyone can provide solution for me? thanks.
|
|
|
|
|
I also stuck in this issue. Anybody was fixed it? Please help me. Thanks!
|
|
|
|
|
I were fix this issue.
We using "IXMLDOMNodePtr" replace for "IXMLDOMNode*" accept these functions:
MSXML2::IXMLDOMNode* Interface();
MSXML2::IXMLDOMNode* Detach();
And we does not using Detach() when GetNode.
for examle:
MSXML2::IXMLDOMNode* CXmlNodeWrapper::GetNode(LPCTSTR nodeName)
--->>
MSXML2::IXMLDOMNodePtr CXmlNodeWrapper::GetNode(int nodeIndex)
return m_xmlnode->selectSingleNode(nodeName).Detach();
-->>
return m_xmlnode->selectSingleNode(nodeName);
|
|
|
|
|
Hi,
Nice class but i am having problem using it to remove the node. I call RemoveNode and then it does not compile. Here is what i have tried.
xmlNode = m_xmlDownloadList.AsNode();
CXmlNodeWrapper resultNode(xmlNode.FindNode("//File[@Path='1'"));
if ( resultNode.IsValid() )
{
xmlNode.RemoveNode(resultNode);
}
It gives a compile time error:
c:\program files\microsoft visual studio\vc98\include\comip.h(74) : error C2451: conditional expression of type 'const class CXmlNodeWrapper' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Documents and Settings\nak\My Documents\Downloads\xmlview\XMLViewDlg.cpp(285) : see reference to function template instantiation '__thiscall _com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMNode,&struct __s_GUID _GUID_2933bf80_7b36_11d2_b
20e_00c04f983e60> >::_com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMNode,&struct __s_GUID _GUID_2933bf80_7b36_11d2_b20e_00c04f983e60> >(const class CXmlNodeWrapper &)' being compiled
I also tried this
xmlNode = m_xmlDownloadList.AsNode();
CXmlNodeWrapper resultNode(xmlNode.FindNode("//File[@Path='1'"));
if ( resultNode.IsValid() )
{
xmlNode.RemoveNode(&resultNode); // passing reference
}
I get
c:\program files\microsoft visual studio\vc98\include\comip.h(690) : error C2039: 'QueryInterface' : is not a member of 'CXmlNodeWrapper'
c:\documents and settings\nak\my documents\downloads\xmlview\xmlnodewrapper.h(16) : see declaration of 'CXmlNodeWrapper'
c:\program files\microsoft visual studio\vc98\include\comip.h(75) : see reference to function template instantiation 'long __thiscall _com_ptr_t<class _com_IIID<struct MSXML2::IXMLDOMNode,&struct __s_GUID _GUID_2933bf80_7b36_11d2_b20e_00c04f
983e60> >::_QueryInterface(class CXmlNodeWrapper *const & )' being compiled
I am really confused what can be the issue. I can see the reasons for the errors but then how can i remove a node using your class. Please help, i need to work out something urgent. No complex code i have written, only inserted 5 nodes and they were inserted and then trying to remove a node. Thanks in Advance
|
|
|
|
|
Hi,
No help provided on this article anymore? I am having issues in find node too. It will be great if you can share a helping hand on how to use it because sample you have given is very basic and does not really use all of the functions.
Thanks
|
|
|
|
|
Hi decentsmile, sorry to keep ypu waiting I wasn't around for a while...
How ever from your code it is impossible to figure out what is wrong...
Please send me a sample project (including the article's files) to tempo001 at rdvsystems dot com
And I'll try to figure out what is wrong.
Creative minds - create creative creations!
|
|
|
|
|
Hi..any update on this issue? I am oso working at this removenode with similar problem...
|
|
|
|
|
When I use InsertNode it adds the attribute "xmlns" to the node.
ie the code
CSULXmlNodeWrapper nodRoot = m_xmlDoc.AsNode();
CSULXmlNodeWrapper nodSection = nodRoot.InsertNode(m_DocumentNode.NumNodes(), "Welcome");
CSULXmlNodeWrapper nodProperty = nodSection.InsertNode(0, "Message");
nodProperty.SetText("0");
adds
<Welcome xmlns=""><Message>0</Message></Welcome>
to the xml file. Whereas I want
<Welcome><Message>0</Message></Welcome>
How can I avoid this?
TIA
|
|
|
|
|
Hai Alex,
I am new student in learn XML language...
Could you help me...?
I find my difficulty when I want print data in xml language
For example I have 10 records then I want print
Test1, Test2, Test 3, Test4, then print Sample1, and the looping
Print again for Test1, Test2, Test3, Test4, and Then Print Sample2.
Thanks for the help.
|
|
|
|
|
Dear Alex:
Thanks for your great job.
I also find your class had something is needed to adjust for Unicode project.
I don't know how to mail you straight by codeproject, and your blog also can't link with. So, if you would like to see what I been changed. Please mail me, I would like to mail you that my added changes.
Sincerely,
|
|
|
|