osgEarth 2.1.1
Functions

anonymous_namespace{XmlUtils.cpp} Namespace Reference

Functions

XmlAttributes getAttributes (const char **attrs)
void processNode (XmlElement *parent, TiXmlNode *node)
void removeDocType (std::string &xmlStr)

Function Documentation

XmlAttributes anonymous_namespace{XmlUtils.cpp}::getAttributes ( const char **  attrs)

Definition at line 280 of file XmlUtils.cpp.

    {
        XmlAttributes map;
        const char** ptr = attrs;
        while( *ptr != NULL )
        {
            std::string name = *ptr++;
            std::string value = *ptr++;
            std::transform( name.begin(), name.end(), name.begin(), tolower );
            map[name] = value;
        }
        return map;
    }
void anonymous_namespace{XmlUtils.cpp}::processNode ( XmlElement parent,
TiXmlNode node 
)

Definition at line 294 of file XmlUtils.cpp.

    {
        XmlElement* new_element = 0;
        switch (node->Type())
        {
        case TiXmlNode::TINYXML_ELEMENT:
            {
                TiXmlElement* element = node->ToElement();
                std::string tag = element->Value();
                std::transform( tag.begin(), tag.end(), tag.begin(), tolower);

                //Get all the attributes
                XmlAttributes attrs;
                TiXmlAttribute* attr = element->FirstAttribute();
                while (attr)
                {
                    std::string name  = attr->Name();
                    std::string value = attr->Value();
                    std::transform( name.begin(), name.end(), name.begin(), tolower);
                    attrs[name] = value;
                    attr = attr->Next();
                }

                //All the element to the stack
                new_element = new XmlElement( tag, attrs );
                parent->getChildren().push_back( new_element );
            }
            break;
        case TiXmlNode::TINYXML_TEXT:
            {
                TiXmlText* text = node->ToText();
                std::string data( text->Value());
                parent->getChildren().push_back( new XmlText( data ) );
            }
            break;
        }    

        XmlElement* new_parent = new_element ? new_element : parent;
        TiXmlNode* child;
        for (child = node->FirstChild(); child != 0; child = child->NextSibling())
        {    
            processNode( new_parent, child );
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void anonymous_namespace{XmlUtils.cpp}::removeDocType ( std::string &  xmlStr)

Definition at line 340 of file XmlUtils.cpp.

    {
        //TinyXML has an issue with parsing DTDs.  See http://www.grinninglizard.com/tinyxmldocs/index.html
        //We need to remove any !DOCTYPE block that appears in the XML before parsing to avoid errors.
        std::string::size_type startIndex = xmlStr.find("<!DOCTYPE");
        if (startIndex == xmlStr.npos) return;

        std::string::size_type endIndex = startIndex;
        int numChildElements = 0;
        //We've found the first index of the <!DOCTYPE, now find the index of the closing >
        while (endIndex < xmlStr.size())
        {
            endIndex+=1;
            if (xmlStr[endIndex] == '<')
            {
                numChildElements++;
            }
            else if (xmlStr[endIndex] == '>')
            {
                if (numChildElements == 0)
                {
                    break;
                }
                else
                {
                    numChildElements--;
                }
            }
        }

        //Now, replace the <!DOCTYPE> element with whitespace
        xmlStr.erase(startIndex, endIndex - startIndex + 1);
    }

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines