Hi,
I want to read the values from the reg.xml file. I tried in several methods using FirstChild.NodeValue()/NextSibling.Nodevalue/NextSiblingbyelements etc.,
The working code is down below. But the code seems to be lengthy and suspect some thing shortcut must be there to extract the values.
Not like converting to QNodeList,assisgn to domNode and again Qstring.
Is this code is right, Since If 50-70 xml enteries there, Then there will be performance issue. Kindly suggest.
reg.xml
-----------=
<?xml version="1.0" encoding="UTF-8"?>
<Download>
<Maps MapSysID="0">
<Title>MINOffice</Title>
<itemId>dc96f92c410d4b93f0</itemId>
<description>General map - 1 used for testing including thumbnail</description>
<created>Wed Aug 31 09:38:49 2016 GMT+0100</created>
<modified>Wed Aug 31 09:56:07 2016 GMT+0100</modified>
<owner>manoharmdev</owner>
<url>http://www.arssd.com/sharing/rest/content/items/dc96f92c410d4b93f0</url>
<thumbnailUrl>http://www.arssd.com/sharing/rest/content/items/dc96f92c410d4b93f0/info/thumbnail/ThumbNail2.jpg</thumbnailUrl>
<size>-1</size>
<IsActive>1</IsActive>
<EntryDate>Tuesday, October 04, 2016</EntryDate>
</Maps>
<Maps MapSysID="1">
<Title>Prefecture</Title>
<itemId>83d1c9aaf9d04e60a8c67</itemId>
<description>CAR map-2 for testing purpose</description>
<created>Wed Aug 31 09:52:23 2016 GMT+0100</created>
<modified>Wed Aug 31 09:54:59 2016 GMT+0100</modified>
<owner>manoharmdev</owner>
<url>http://www.arssd.com/sharing/rest/content/items/83d1c9aaf9d04e60a8c67</url>
<thumbnailUrl>http://www.arssd.com/sharing/rest/content/items/83d1c9aaf9d04e60a8c67/info/thumbnail/ThumbNail2.jpg</thumbnailUrl>
<size>-1</size>
<IsActive>1</IsActive>
<EntryDate>Tuesday, October 04, 2016</EntryDate>
</Maps>
</Download>
<?xml version="1.0" encoding="UTF-8"?>
<Download>
<Maps MapSysID="0">
<Title>MINOffice</Title>
<itemId>dc96f92c410d4b93f0</itemId>
<description>General map - 1 used for testing including thumbnail</description>
<created>Wed Aug 31 09:38:49 2016 GMT+0100</created>
<modified>Wed Aug 31 09:56:07 2016 GMT+0100</modified>
<owner>manoharmdev</owner>
<url>http://www.arssd.com/sharing/rest/content/items/dc96f92c410d4b93f0</url>
<thumbnailUrl>http://www.arssd.com/sharing/rest/content/items/dc96f92c410d4b93f0/info/thumbnail/ThumbNail2.jpg</thumbnailUrl>
<size>-1</size>
<IsActive>1</IsActive>
<EntryDate>Tuesday, October 04, 2016</EntryDate>
</Maps>
<Maps MapSysID="1">
<Title>Prefecture</Title>
<itemId>83d1c9aaf9d04e60a8c67</itemId>
<description>CAR map-2 for testing purpose</description>
<created>Wed Aug 31 09:52:23 2016 GMT+0100</created>
<modified>Wed Aug 31 09:54:59 2016 GMT+0100</modified>
<owner>manoharmdev</owner>
<url>http://www.arssd.com/sharing/rest/content/items/83d1c9aaf9d04e60a8c67</url>
<thumbnailUrl>http://www.arssd.com/sharing/rest/content/items/83d1c9aaf9d04e60a8c67/info/thumbnail/ThumbNail2.jpg</thumbnailUrl>
<size>-1</size>
<IsActive>1</IsActive>
<EntryDate>Tuesday, October 04, 2016</EntryDate>
</Maps>
</Download>
To copy to clipboard, switch view to plain text mode
C++ code for reading the xml
----------------------------------------------:
QDomNodeList objQDomNodeListOne
= docElem.
elementsByTagName("Maps");
QDomNode objQDomNodeone
= objQDomNodeListOne.
at(0);
int intDomNode = objQDomNodeListOne.count();
for(int i = 0; i < objQDomNodeListOne.count(); i++)
{
QDomNode elm
= objQDomNodeListOne.
at(i
);
if(elm.isElement())
{
QDomNodeList qNdlstdescription
= e.
elementsByTagName("description");
QDomNodeList qNdlstcreated
= e.
elementsByTagName("created");
QDomNodeList qNdlstmodified
= e.
elementsByTagName("modified");
QDomNodeList qNdlstthumbnailUrl
= e.
elementsByTagName("thumbnailUrl");
QDomNodeList qNdlstIsActive
= e.
elementsByTagName("IsActive");
QDomNodeList qNdlstEntryDate
= e.
elementsByTagName("EntryDate");
QDomNode qNodeTitle
= qNdlstTitle.
at(0);
QDomNode qNodeitemId
= qNdlstitemId.
at(0);
QDomNode qNodedescription
= qNdlstdescription.
at(0);
QDomNode qNodecreated
= qNdlstcreated.
at(0);
QDomNode qNodemodified
= qNdlstmodified.
at(0);
QDomNode qNodeowner
= qNdlstowner.
at(0);
QDomNode qNodethumbnailUrl
= qNdlstthumbnailUrl.
at(0);
QDomNode qNodeIsActive
= qNdlstIsActive.
at(0);
QDomNode qNodeEntryDate
= qNdlstEntryDate.
at(0);
strTitle = qNodeTitle.firstChild().nodeValue();
strItemId = qNodeitemId.firstChild().nodeValue();
strDescription = qNodedescription.firstChild().nodeValue();
strCreated = qNodecreated.firstChild().nodeValue();
strModified = qNodemodified.firstChild().nodeValue();
strOwner = qNodeowner.firstChild().nodeValue();
strUrl = qNodeurl.firstChild().nodeValue();
strThumbnailUrl = qNodethumbnailUrl.firstChild().nodeValue();
strSize = qNodesize.firstChild().nodeValue();
strIsActive = qNodeIsActive.firstChild().nodeValue();
strEntryDate = qNodeEntryDate.firstChild().nodeValue();
}
}
QDomNodeList objQDomNodeListOne = docElem.elementsByTagName("Maps");
QDomNode objQDomNodeone = objQDomNodeListOne.at(0);
int intDomNode = objQDomNodeListOne.count();
QString strTitle ;
QString strItemId ;
QString strDescription;
QString strCreated ;
QString strModified ;
QString strOwner ;
QString strUrl ;
QString strThumbnailUrl;
QString strSize;
QString strIsActive;
QString strEntryDate;
for(int i = 0; i < objQDomNodeListOne.count(); i++)
{
QDomNode elm = objQDomNodeListOne.at(i);
if(elm.isElement())
{
QDomElement e = elm.toElement();
QDomNodeList qNdlstTitle = e.elementsByTagName("Title");
QDomNodeList qNdlstitemId = e.elementsByTagName("itemId");
QDomNodeList qNdlstdescription = e.elementsByTagName("description");
QDomNodeList qNdlstcreated = e.elementsByTagName("created");
QDomNodeList qNdlstmodified = e.elementsByTagName("modified");
QDomNodeList qNdlstowner = e.elementsByTagName("owner");
QDomNodeList qNdlsturl = e.elementsByTagName("url");
QDomNodeList qNdlstthumbnailUrl = e.elementsByTagName("thumbnailUrl");
QDomNodeList qNdlstsize = e.elementsByTagName("size");
QDomNodeList qNdlstIsActive = e.elementsByTagName("IsActive");
QDomNodeList qNdlstEntryDate = e.elementsByTagName("EntryDate");
QDomNode qNodeTitle = qNdlstTitle.at(0);
QDomNode qNodeitemId = qNdlstitemId.at(0);
QDomNode qNodedescription = qNdlstdescription.at(0);
QDomNode qNodecreated = qNdlstcreated.at(0);
QDomNode qNodemodified = qNdlstmodified.at(0);
QDomNode qNodeowner = qNdlstowner.at(0);
QDomNode qNodeurl = qNdlsturl.at(0);
QDomNode qNodethumbnailUrl = qNdlstthumbnailUrl.at(0);
QDomNode qNodesize = qNdlstsize.at(0);
QDomNode qNodeIsActive = qNdlstIsActive.at(0);
QDomNode qNodeEntryDate = qNdlstEntryDate.at(0);
strTitle = qNodeTitle.firstChild().nodeValue();
strItemId = qNodeitemId.firstChild().nodeValue();
strDescription = qNodedescription.firstChild().nodeValue();
strCreated = qNodecreated.firstChild().nodeValue();
strModified = qNodemodified.firstChild().nodeValue();
strOwner = qNodeowner.firstChild().nodeValue();
strUrl = qNodeurl.firstChild().nodeValue();
strThumbnailUrl = qNodethumbnailUrl.firstChild().nodeValue();
strSize = qNodesize.firstChild().nodeValue();
strIsActive = qNodeIsActive.firstChild().nodeValue();
strEntryDate = qNodeEntryDate.firstChild().nodeValue();
}
}
To copy to clipboard, switch view to plain text mode
reply quote 0
Bookmarks