PDA

View Full Version : Default attributes values when reading XML document corresponding to DTD



discretus
9th March 2010, 13:02
Hello.

I've got next problem.

I made my own DTD scheme, then I built corresponding XML and then I tried to read data from it using the next QT classes:
QDomDocument
QDomElement
QDomNode

DTD:


......
<!DOCTYPE GCAD3_HOST_GUI_SCHEME [
<!ELEMENT GCAD3_HOST_GUI_SCHEME (ACTION_MANAGER, CONFIGURATION_MANAGER, MAIN_MENU, FUNCTION_EXPLORER, TOOL_BARS)>
<!ATTLIST GCAD3_HOST_GUI_SCHEME
AUTOMATIC_LOAD_STATIC_PART (1|0) #FIXED "1"
AUTOMATIC_LOAD_DYNAMIC_PART (1|0) "1">
......


XML:


....
<GCAD3_HOST_GUI_SCHEME AUTOMATIC_LOAD_DYNAMIC_PART="0">
....


Attribute AUTOMATIC_LOAD_STATIC_PART is omitted as you can see!

Then I was trying to extract the current value of this attribute from C++.

C++:


....
QFile* v_xml_gui_file = new QFile(v_curr_xml);

if (v_xml_gui_file->open(QIODevice::ReadOnly))
{
auto_ptr<QDomDocument> v_xml_gui(new QDomDocument());
QString v_parseErrors;
int v_errLine, v_errCol;
if (!v_xml_gui->setContent(v_xml_gui_file,true,&v_parseErrors,&v_errLine,&v_errCol) )
{return;}
QDomElement root = v_xml_gui->documentElement();
root.nodeType()
QDomNode n = root.firstChild();

QString v_defValue1, v_defValue2;
int v_static= root.attribute("AUTOMATIC_LOAD_STATIC_PART",v_defValue1).toInt();
int v_dynamic= root.attribute("AUTOMATIC_LOAD_DYNAMIC_PART",v_defValue2).toInt();
}
....


Result of execution of this code was the next:
v_static == 0 (but "1" was expected)
v_defValue1 == 0

v_dynamic == 0 (but "1" was expected)
v_defValue1 == 0

I use: Visual Studio 2008, WindowsXP (platform), QT 4.3.3

Is there anyone who know what I have done wrong ?

Thanks for participate :)