예제 #1
0
파일: XmlUtils.cpp 프로젝트: jehc/osgearth
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;
    }
}
예제 #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() ) );
    }
}
예제 #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;
    }
}