QDomDocument question

I want to read some values from a XML file by QDomDocument class.  But I always fail. So I hope someone know how to read atributes with QDomDocument . My XML file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xbel>
<xbel name="project" version="1.0" date="Di Jul 21 2015" size="0" item_count="0">
  <disk projecttype="1" name="Disk[New]"  arranger=""/>

Open in new window

I want to read the attribute projecttype that can stay in front or behind name. (Not my idea).

Any help will be welcome.
Ingo FoersterProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
>> But I always fail.
Example code with details of the errors you get would be useful.
Ingo FoersterProgrammerAuthor Commented:
I have found some code in the internet and have rewritten to my needs. Works like a charme. Here is the code I use:

  QDomDocument doc;

  int nDiskType = -1;

  QDomNodeList diskList = doc.elementsByTagName("disk");

  for (int i = 0; i < diskList.count(); i++)
      if (i < diskList.count())
          QDomElement node = diskList.at(i).toElement();
          if (node.hasAttribute("projecttype"))
              nDiskType = node.attribute("projecttype").toInt();


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ingo FoersterProgrammerAuthor Commented:
Own solution. Published to share with people here.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.