Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading xml through Qt
Forum Updated to NodeBB v4.3 + New Features

Reading xml through Qt

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BibekKumar
    wrote on last edited by
    #1

    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 .

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerManu
        wrote on last edited by
        #3

        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/.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BibekKumar
          wrote on last edited by
          #4

          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 .

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              [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.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BibekKumar
                wrote on last edited by
                #7

                Thanks Andre ..Your answer always helps me a lot ...

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved