Re: c++ recursive class
Well, in .H file I put:
#include "tinyxml/tinyxml.h"
class documentTinyNode : public TiXmlNode
{
public:
documentTinyNode(); // CTOR object TiXmlNode
~documentTinyNode() { };
LPCSTR GetAttribute( LPCSTR attributename ) { return ToElement
()->Attribute( attributename ); } // function class returns
attribute
void SetAttribute( LPCSTR attributename, LPCSTR
attributevalue ) { ToElement()->SetAttribute( attributename,
attributevalue ); } // function class sets attribute
documentTinyNode* Node( LPCSTR nodename, LPCSTR
attributenodename, LPCSTR attributetosearch ) // function class
returns new node
{
FirstChild(nodename);
LPCSTR currentnodename = ToElement()->Attribute
(attributenodename);
while ( (currentnodename != NULL) && (strcmp
(currentnodename, attributetosearch) != 0) ) {
IterateChildren(nodename , this);
currentnodename = ToElement()->Attribute
(attributenodename);
}
return ( (currentnodename != NULL) ? this : NULL );
}
};
class documentTinyXML : public TiXmlDocument
{
public:
documentTinyXML( LPCSTR xmlfilename ); // CTOR object
TiXmlDocument
~documentTinyXML() { };
documentTinyNode* Node( LPCSTR nodename, LPCSTR
attributenodename, LPCSTR attributetosearch ) // function returns
object class TiXmlNode
{
documentTinyNode::Node(nodename, attributenodename,
attributetosearch);
}); // function returns object class TiXmlNode
};
indeed in .CPP file I put:
documentTinyXML::documentTinyXML( LPCSTR xmlfilename )
{
if (!LoadFile( xmlfilename ))
AfxGetMainWnd()->MessageBox(_T("Error! Can't load xml
configuration file!\nIt could be not present or broken."), _T("MFC
Analyzer GUI"), MB_ICONSTOP | MB_OK);
}
void Ctest_tinyxmlDlg::OnBnClickedButton1()
{
//<?xml version="1.0" ?>
//<analyzer>
// <module name="system-manager">
// <sentence header="enableModules">
// <row-info name="system-manager"
value="1" />
// <row-info name="input-manager"
value="1" />
// <row-info name="output-manager"
value="1" />
// </sentence>
// </module>
// <module name="input-manager">
// <sentence header="output-type">
// <row-info name="out" value="1"
description="whatever-it-is" />
// </sentence>
// </module>
// <module name="output-manager">
// <sentence header="output-type">
// <row-info name="out" value="1"
description="whatever-it-is" />
// </sentence>
// </module>
//</analyzer>
documentTinyXML* xmldocument = new documentTinyXML
( "example.xml" );
LPCSTR pValue = xmldocument->Node("module","name","system-
manager")->Node("sentence","header","enableModules")->Node("row-
info","name","system-manager")->GetAttribute("value");
GetDlgItem(IDC_EDIT1)->SetWindowText( (LPCTSTR)pValue );
}
As you can see I'd like to start from TiXmlDocument's type member
variable, getting deeper nodes to decide where to navigate since I
could have same sentences in different sublevels=85 how I could do
that?...
Thanks
ciao
Luigi