Unsolved How do we store a parsed xml file in Qt?
-
Hi
What data structure that works best would depend on what you need to do with after.
Do you need this data to be exposed to QML ?
If yes, we should use a data type that QML understand then.
Also Qmap would allow you to look up that data using a key but do you need that ? -
Hi, Thank you for helping me at this time.
yes, I need this data to be exposed to QML.
Yes, I need to store this data in keys and values style.here's where I am going wrong with what data structure should I use. can you suggest me a data structure that understands the QML?
-
@varshit said in How do we store a parsed xml file in Qt?:
e a data structure that understands the QML?
Are you trying to create a UI in QML based on that XML? If so it looks like you may want to start creating QML components as you parse the XML then
-
Hi
We want to create a UI inQML based on that XML.
We created the QML components using QComponentsNow I want to store the parsed XML file in a QMap or QHash or etc or in any container class.
Please help me with the storing part.Thank you
-
@varshit What exact problem do you have with storing key/value pairs from XML in QMap/QHash which you already print out?
-
@varshit
May I ask again why you wish to try to turn this intoQMap
orQHash
?You're going to have to store it as a "recursive tree" of
QMap
/QHash
es, to allow for the structure and avoid duplicates. For example, an XML document could easily have multiple nodes named/a/b
, so you cannot easily just use a "flat" key for your maps/hashes to avoid all the nesting....I wrote earlier that you already have a parsed structure which captures the whole XML document. And it's a
QDomDocument
withQDomNode
s. You don't have to do your own parsing/copying, because it's done for you, and you can search/walk that as required. It can also serialize to/deserialize from text. So you're done!? -
Hi
Now my main part is to store that output data (image inserted above) in [QMap<QString, QMap<QString, QString>>;] this data structure.Thank you
-
Hi
I am not able to understand or figure out how to store these Key-value pairs in the above-mentioned data structure. -
@varshit
So your top-levelQMap<QString, QMap<QString, QString>>
will have keysbreakfast_menu
,Veg
, etc. Each one will have its ownQMap<QString, QString>
as value. Those innerQMap
s will have keysmenu1
,menu2
with valuesveg
,non-veg
, etc. Nothing else to say. -
@varshit said in How do we store a parsed xml file in Qt?:
[QMap<QString, QMap<QString, QString>>;]
It would be like
using MemberMap = QMap<QString, QString>; QMap<QString, MemberMap> items; MemberMap m1; m1["text"]="value"; ... items["ID"]=m1; MemberMap m2; m1["text"]="value"; ... items["ID"]=m2;
But using your real data for key value and ID