Ejemplo n.º 1
0
static void
storeNode( const XmlNode* node, int depth, std::ostream& out )
{
    out << std::fixed; // always use fixed notation

    for( int k=0; k<depth*INDENT; k++ ) out << " ";

    if ( node->isElement() )
    {
        XmlElement* e = (XmlElement*)node;
        out << "<" << e->getName();
        for( XmlAttributes::iterator a = e->getAttrs().begin(); a != e->getAttrs().end(); a++ )
        {
            out << " " << a->first << "=" << "\"" << a->second << "\"";
        }
        out << ">" << std::endl;
        for( XmlNodeList::iterator i = e->getChildren().begin(); i != e->getChildren().end(); i++ )
        {
            storeNode( i->get(), depth+1, out );
        }
        for( int k=0; k<depth*INDENT; k++ ) out << " ";
        out << "</" << e->getName() << ">" << std::endl;
    }
    else if ( node->isText() )
    {
        XmlText* t = (XmlText*)node;
        const std::string& text = t->getValue();
        if ( text.find_first_of( "<&" ) != std::string::npos )
            out << "<![CDATA[" << text << "]]>" << std::endl;
        else
            out << text << std::endl;
    }
}
Ejemplo n.º 2
0
static void
storeNode( const XmlNode* node, TiXmlNode* parent)
{
    if (node->isElement())
    {
        XmlElement* e = (XmlElement*)node;
        TiXmlElement* element = new TiXmlElement( e->getName().c_str() );
        //Write out all the attributes
        for( XmlAttributes::iterator a = e->getAttrs().begin(); a != e->getAttrs().end(); a++ )
        {
            element->SetAttribute(a->first.c_str(), a->second.c_str() );            
        }

        //Write out all the child nodes
        for( XmlNodeList::iterator i = e->getChildren().begin(); i != e->getChildren().end(); i++ )
        {
            storeNode( i->get(), element );
        }
        parent->LinkEndChild( element );
    }
    else if (node->isText())
    {
        XmlText* t = (XmlText*)node;
        parent->LinkEndChild( new TiXmlText( t->getValue().c_str() ) );
    }
}
Ejemplo n.º 3
0
static void
storeNode( XmlNode* node, int depth, std::ostream& out )
{
    for( int k=0; k<depth*INDENT; k++ )
        out << " ";

    if ( node->isElement() )
    {
        XmlElement* e = (XmlElement*)node;
        out << "<" << e->getName();
        for( XmlAttributes::iterator a = e->getAttrs().begin(); a != e->getAttrs().end(); a++ )
        {
            out << " " << a->first << "=" << "\"" << a->second << "\"";
        }
        if ( e->getChildren().empty())
        {
        	out << "/>" << std::endl;
        }
        else
        {
        	out << ">" << std::endl;
			for( XmlNodeList::iterator i = e->getChildren().begin(); i != e->getChildren().end(); i++ )
			{
				storeNode( i->get(), depth+1, out );
			}
		    for( int k=0; k<depth*INDENT; k++ )
		        out << " ";
			out << "</" << e->getName() << ">" << std::endl;
        }

    }
    else if ( node->isText() )
    {
        XmlText* t = (XmlText*)node;
        out << t->getValue() << std::endl;
    }
}