Reading xml through Qt
-
I am new to Qt and XML . Please help me on solving this . I shall be greatful to you .
Here is my XML file format .@< SiteSpecific>
< SitesList>LocA;LocB;LocC< /SitesList>
< LocA>
< MaterialList>Material_A;Material_B</MaterialList> <Material Name="Material_A"> <TemperatureList>-65;70;300;400;1000</TemperatureList> <Density Value="0.286"/> <PoissonRatio Value="0.27"/> <Property tempid="01" temp="-65"> <Modulus Value="32.77E+6"/> <Alpha Value="8.15E-6"/> <YieldStrength Value="33.90E+3"/> </Property> <Property tempid="02" temp="70"> <Modulus Value="29.00E+6"/> <Alpha Value="8.55E-6"/> <YieldStrength Value="30.00E+3"/>
= </Property>
<Property tempid="03" temp="300"> <Modulus Value="27.50E+6"/> <Alpha Value="9.26E-6"/> <YieldStrength Value="22.40E+3"/> </Property> </Material>
</LocA>
< LocB>< MaterialList>Material_C;Material_D</MaterialList> <Material Name="Material_C"> <TemperatureList>-65;70;300;400;1000</TemperatureList> <Density Value="0.286"/> <PoissonRatio Value="0.27"/> <Property tempid="01" temp="-65"> <Modulus Value="32.77E+6"/> <Alpha Value="8.15E-6"/> <YieldStrength Value="33.90E+3"/> </Property> <Material Name="Material_D"> <TemperatureList>-65;70;300;400;1000</TemperatureList> <Density Value="0.286"/> <PoissonRatio Value="0.27"/> <Property tempid="01" temp="-65"> <Modulus Value="32.77E+6"/> <Alpha Value="8.15E-6"/> <YieldStrength Value="33.90E+3"/> </Property> </Material>
</LocB>@
From the above file format i have to extract Materialist(e.g Material_A , Material_B , Material_C , Material_D) , Temperaturelist(e.g. -65,70,300,400,1000) and all the properties (Modulus , alpha and yieldstrength )based on tempid for LocA and LocB . -
Qt has three XML parsing systems available. The DOM model, the SAX model and the XML Stream model (the latter being Qt specific). I usually prefer the latter, revolving around [[doc:QXmlStreamReader]]. Those classes are used for straightforward XML parsing. You could also considder using XQuery, using the QtXmlPatterns module. It allows formulating queries to run on the XML structured data, so you can easily retreive the lists you need.
-
Your File seems to have an error in line 27.
I've found xml handling with Qt unnecessarily inefficient (from the programming point of view), so I've written my own wrappers which make it especially easy, see "QXmlPutGet":http://www.workslikeclockwork.com/index.php/components/xml-classes-for-qt/.
-
I am not going to read the XML file at once . The tag name will be given to the programme during runtime . Please suggest for this kind fo requirement which way i should go , QXmlStreamReader or
QDomDocument .Please suggest some coding concept based on it ..
Thanks in adv . -
You can take a look at "QXmlStreamReader to parse XML in Qt":http://www.developer.nokia.com/Community/Wiki/QXmlStreamReader_to_parse_XML_in_Qt example that uses QXmlStreamReader for parsing the xml file.
-
[quote author="DerManu" date="1354751958"]Your File seems to have an error in line 27.
I've found xml handling with Qt unnecessarily inefficient (from the programming point of view), so I've written my own wrappers which make it especially easy, see "QXmlPutGet":http://www.workslikeclockwork.com/index.php/components/xml-classes-for-qt/.[/quote]
Looks like an interesting approach, although I still have to read much of the blog. I do have one minor gripe with it though: the use of the Q prefix makes it look like a class that is part of the Qt library, while it is not. Please get a different prefix, like Qxt and Qwt are doing. You can even register one.
[quote author="Vikuseth" date="1354770809"]I am not going to read the XML file at once . The tag name will be given to the programme during runtime . Please suggest for this kind fo requirement which way i should go , QXmlStreamReader or QDomDocument .[/quote]
If you really just need to create lists of values of specific tag types, I'd really look into using XQuery. -
Thanks Andre ..Your answer always helps me a lot ...