falconium
23rd March 2011, 20:42
I have the following code, but it doesn't seem to work. First of all, 'fragment' seems to be empty with debugger despite I call createDocumentFragment().
Below part for parsing XML document inside 'data' is to ensure that the source has data. All iterated item has.
Why fragment is empty? Thanks!
if (mergedXML.documentElement().isNull())
{
QDomElement root = mergedXML.createElement("MergedMeasurements");
mergedXML.appendChild(root);
}
foreach (XMLStruct data, mainXMLList)
{
QDomDocumentFragment fragment = data.getXMLDocument()->createDocumentFragment(); // This creates the fragment from QDomDocument.
mergedXML.firstChild().appendChild(fragment);
for (int i=0; i<data.getXMLDocument()->childNodes().count(); i++)
{
if (data.getXMLDocument()->childNodes().at(i).nodeName()=="OMeS")
for (int j=0; j<data.getXMLDocument()->childNodes().at(i).childNodes().count(); j++)
{
if (data.getXMLDocument()->childNodes().at(i).childNodes().at(j).nodeName()=="PMSetup")
{
for (int k=0; k<data.getXMLDocument()->childNodes().at(i).childNodes().at(j).childNodes() .count(); k++)
{
if (data.getXMLDocument()->childNodes().at(i).childNodes().at(j).childNodes() .at(k).nodeName()=="extraInfoSetup")
{
QDomNode x = data.getXMLDocument()->childNodes().at(i).childNodes().at(j).childNodes() .at(k);
log(x.firstChildElement("measurementName").text());
}
}
}
}
}
}
Below part for parsing XML document inside 'data' is to ensure that the source has data. All iterated item has.
Why fragment is empty? Thanks!
if (mergedXML.documentElement().isNull())
{
QDomElement root = mergedXML.createElement("MergedMeasurements");
mergedXML.appendChild(root);
}
foreach (XMLStruct data, mainXMLList)
{
QDomDocumentFragment fragment = data.getXMLDocument()->createDocumentFragment(); // This creates the fragment from QDomDocument.
mergedXML.firstChild().appendChild(fragment);
for (int i=0; i<data.getXMLDocument()->childNodes().count(); i++)
{
if (data.getXMLDocument()->childNodes().at(i).nodeName()=="OMeS")
for (int j=0; j<data.getXMLDocument()->childNodes().at(i).childNodes().count(); j++)
{
if (data.getXMLDocument()->childNodes().at(i).childNodes().at(j).nodeName()=="PMSetup")
{
for (int k=0; k<data.getXMLDocument()->childNodes().at(i).childNodes().at(j).childNodes() .count(); k++)
{
if (data.getXMLDocument()->childNodes().at(i).childNodes().at(j).childNodes() .at(k).nodeName()=="extraInfoSetup")
{
QDomNode x = data.getXMLDocument()->childNodes().at(i).childNodes().at(j).childNodes() .at(k);
log(x.firstChildElement("measurementName").text());
}
}
}
}
}
}