diff --git a/include/osgDB/XmlParser b/include/osgDB/XmlParser index 6631b7517..fc6b5bf82 100644 --- a/include/osgDB/XmlParser +++ b/include/osgDB/XmlParser @@ -132,9 +132,13 @@ class OSGDB_EXPORT XmlNode : public osg::Referenced bool read(Input& input); - bool write(std::ostream& fout) const; + bool write(std::ostream& fout, const std::string& indent = "") const; bool writeString(std::ostream& fout, const std::string& str) const; + protected: + + bool writeChildren(std::ostream& fout, const std::string& indent) const; + bool writeProperties(std::ostream& fout) const; }; } diff --git a/src/osgDB/XmlParser.cpp b/src/osgDB/XmlParser.cpp index 71729c03e..ebad4413f 100644 --- a/src/osgDB/XmlParser.cpp +++ b/src/osgDB/XmlParser.cpp @@ -307,6 +307,7 @@ bool XmlNode::read(Input& input) { ++input; osg::notify(osg::INFO)<<"tag is closed correctly"<type = ATOM; } else osg::notify(osg::NOTICE)<<"Error: tag is not closed correctly"<first<<"\""; - writeString(fout,oitr->second); - fout<<"\""<"<write(fout); - } + writeChildren(fout, indent); return true; } case(NODE): - { - fout<<"<"<first<<"=\""; - writeString(fout,oitr->second); - fout<<"\""; - } - - if (children.empty() && contents.empty()) - { - fout<<" />"<"; - for(Children::const_iterator citr = children.begin(); - citr != children.end(); - ++citr) - { - (*citr)->write(fout); - } - - if (!contents.empty()) writeString(fout,contents); - - fout<<""<first<<"=\""; - writeString(fout,oitr->second); - fout<<"\""; - } + fout<"<write(fout); - } + writeChildren(fout, indent + " "); - fout<<""<"<"<"<"<"<write(fout, indent)) + return false; + } + + return true; +} + +bool XmlNode::writeProperties(std::ostream& fout) const +{ + for(Properties::const_iterator oitr = properties.begin(); + oitr != properties.end(); + ++oitr) + { + fout<<" "<first<<"=\""; + if (!writeString(fout,oitr->second)) + return false; + fout<<"\""; + } + + return true; +}