Display part of an XML file while parsing it

Posted by Andy M on Stack Overflow See other posts from Stack Overflow or by Andy M
Published on 2010-04-12T12:05:13Z Indexed on 2010/04/12 19:33 UTC
Read the original article Hit count: 496

Filed under:
|
|
|
|

Hey,

Consider the following XML file :

<cookbook>
<recipe xml:id="MushroomSoup">
    <title>Quick and Easy Mushroom Soup</title>
    <ingredient name="Fresh mushrooms"
                quantity="7"
                unit="pieces"/>
    <ingredient name="Garlic"
                quantity="1"
                unit="cloves"/>
</recipe>
<recipe xml:id="AnotherRecipe">
    <title>XXXXXXX</title>
    <ingredient name="Tomatoes"
                quantity="8"
                unit="pieces"/>
    <ingredient name="PineApples"
                quantity="2"
                unit="cloves"/>
</recipe>
</cookbook>

Let's say I want to parse this file and gather each recipe as XML, each one as a separated QString.

For example, I would like to have a QString that contains :

<recipe xml:id="MushroomSoup">
    <title>Quick and Easy Mushroom Soup</title>
    <ingredient name="Fresh mushrooms"
                quantity="7"
                unit="pieces"/>
    <ingredient name="Garlic"
                quantity="1"
                unit="cloves"/>
</recipe>

How could I do this ? Do you guys know a quick and clean method to perform this ?

Thanks in advance for your help !

© Stack Overflow or respective owner

Related posts about qt

Related posts about Xml