Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Parsing an XML file using ticpp (tinyxml++) using streaming operators #69

Open
GoogleCodeExporter opened this issue Mar 17, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

I'd like to utilize the streaming operator to parse an XML file with ticpp 
(tinyxml ++ ). I've not been able to find any examples on this. The ticpp 
documentation says only a little bit about streaming support.

I'd like to initialize streaming in with the following:

ifstream in;
in.open( m_sConfigFile, std::ios::in );

if( in.good() )
    in >> *this;
I'm not sure how to write the stream in function:

std::istream & operator >> ( std::istream & in, EffectMgr & r )
{   
    return in;
}
My XML file looks like this:

<? xml version="1.0" ?>

<EffectsMgr>
    <Effect name="textured-phong" >
        <Shader name="textured-phong.vert" type="Vertex" />
        <Shader name="textured-phong.frag" type="Fragment" />
        <VertexClass name="CustomVertex" />
        <Attribute name="VertexPosition" size="3" offset="0" />
        <Attribute name="VertexNormal" size="3" offset="3" />
        <Attribute name="VertexTexCoord" size="3" offset="6" />
    </Effect>
</EffectsMgr>
Are there any examples out there I should check out?

Original issue reported on code.google.com by johnny.m...@gmail.com on 19 Feb 2012 at 12:36

@GoogleCodeExporter
Copy link
Author

I've updated my question, as I've found how to stream in from disk.

I'd like to utilize the streaming operator to parse an XML file with ticpp 
(tinyxml ++ ).  I've not been able to find any examples on this. 

I'd like to initialize streaming in with the following:

    ifstream in;
    in.open( m_sConfigFile, std::ios::in );

    if( in.good() )
        in >> *this;

Here's my solution for the stream in function:

    std::istream & operator >> ( std::istream & in, EffectMgr & r )
    {
        ticpp::Document doc;

        in >> doc;  

        ticpp::Iterator<ticpp::Element> EffectItr;      

        for( EffectItr = EffectItr.begin(doc.FirstChildElement()); EffectItr != EffectItr.end(); EffectItr ++ )
        {       
            // Generate Effect objects
        }

        return in;
    }

My question is how can I write the stream out function?

    std::ostream & operator << ( std::ostream & out, const EffectMgr & r )
    {
        // ????
        return out;
    }

My XML file looks like this:

    <? xml version="1.0" ?>

    <EffectsMgr>
        <Effect name="textured-phong" >
            <Shader name="textured-phong.vert" type="Vertex" />
            <Shader name="textured-phong.frag" type="Fragment" />
            <VertexClass name="CustomVertex" />
            <Attribute name="VertexPosition" size="3" offset="0" />
            <Attribute name="VertexNormal" size="3" offset="3" />
            <Attribute name="VertexTexCoord" size="3" offset="6" />
        </Effect>
        <Effect>
            ...
        </Effect>
    </EffectsMgr>

Original comment by johnny.m...@gmail.com on 20 Feb 2012 at 12:06

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant