mardi 21 avril 2015

Read attribute names and their values from a xml file in Qt using QDomNodeList

This is my xml file.

    <Dictionary EnglishName="English (United States)" CultureName="English (United States)" Culture="en-US">
         <Value Id="ID_OK" Translation="OK" English="OK" />
         <Value Id="ID_Cancel" Translation="Cancel" English="Cancel1" />
         <Value Id="ID_DemoMode" Translation="Demo Mode" English="Demo Mode" />
        <Value Id="ID_PhoneNumberColon" Translation="Phone Number:" English="Phone Number:" />
         <Value Id="ID_FaxNumberColon" Translation="Fax Number:" English="Fax Number:" />
         <Value Id="ID_CustomerColon" Translation="Customer:" English="Customer:" />
         <Value Id="ID_CompanyColon" Translation="Company:" English="Company:" />

I am able to get values of Id,Translation and English perfectly but i am not able to get the values of "EnglishName" ,"CultureName" and "Culture". This is my codesample,

QDomDocument doc("Labguage");
QFile file("English.xml");
if (!file.open(QIODevice::ReadOnly))
         return;

if (!doc.setContent(&file))
{
file.close();
         return;
}
file.close();

    QDomNode root = doc.namedItem("Dictionary");
    QDomNodeList nodeList = root.childNodes();
    if (nodeList.count() > 0)
    {
       for(int iDx = 0;iDx < nodeList.count(); iDx++)
        {
           QString EnglishName(nodeList.at(iDx).attributes().namedItem("EnglishName").nodeValue());
           QString CultureName(nodeList.at(iDx).attributes().namedItem("CultureName").nodeValue());
           QString Culture(nodeList.at(iDx).toElement().attribute("Culture"));

QString Translation(nodeList.at(iDx).attributes().namedItem("Translation").nodeValue()); QString English(nodeList.at(iDx).attributes().namedItem("English").nodeValue()); QString Id(nodeList.at(iDx).toElement().attribute("Id")); qDebug() << "Id: " << Id<

        }
     }
   I got EnglishName,CultureName and Culture as blank,where is my mistake, plz help me .

Thanks

Aucun commentaire:

Enregistrer un commentaire