Index: /OpenSceneGraph/trunk/include/osgDB/XmlParser
===================================================================
--- /OpenSceneGraph/trunk/include/osgDB/XmlParser (revision 10534)
+++ /OpenSceneGraph/trunk/include/osgDB/XmlParser (revision 10943)
@@ -133,7 +133,11 @@
         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;
 };
 
Index: /OpenSceneGraph/trunk/src/osgDB/XmlParser.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgDB/XmlParser.cpp (revision 10930)
+++ /OpenSceneGraph/trunk/src/osgDB/XmlParser.cpp (revision 10943)
@@ -308,4 +308,5 @@
                         ++input;
                         osg::notify(osg::INFO)<<"tag is closed correctly"<<std::endl;
+                        childNode->type = ATOM;
                     }
                     else 
@@ -361,5 +362,5 @@
 }
 
-bool XmlNode::write(std::ostream& fout) const
+bool XmlNode::write(std::ostream& fout, const std::string& indent) const
 {
     switch(type)
@@ -369,89 +370,34 @@
         case(ATOM):
         {
-            fout<<"<"<<name;
-            for(Properties::const_iterator oitr = properties.begin();
-                oitr != properties.end();
-                ++oitr)
-            {
-                fout<<oitr->first<<"\"";
-                writeString(fout,oitr->second);
-                fout<<"\""<<std::endl;
-            }
-            return true;
+            fout<<indent<<"<"<<name;
+            writeProperties(fout);
             fout<<" />"<<std::endl;
+            return true;
         }
         case(ROOT):
         {
-            for(Children::const_iterator citr = children.begin();
-                citr != children.end();
-                ++citr)
-            {
-                (*citr)->write(fout);
-            }
+            writeChildren(fout, indent);
             return true;
         }
         case(NODE):
-        {
-            fout<<"<"<<name;
-            for(Properties::const_iterator oitr = properties.begin();
-                oitr != properties.end();
-                ++oitr)
-            {
-                fout<<" "<<oitr->first<<"=\"";
-                writeString(fout,oitr->second);
-                fout<<"\"";
-            }
-
-            if (children.empty() && contents.empty())
-            {
-                fout<<" />"<<std::endl;
-            }
-            else
-            {
-                fout<<">";
-                for(Children::const_iterator citr = children.begin();
-                    citr != children.end();
-                    ++citr)
-                {
-                    (*citr)->write(fout);
-                }
-
-                if (!contents.empty()) writeString(fout,contents);
-
-                fout<<"</"<<name<<">"<<std::endl;
-            }
-            return true;
-        }
         case(GROUP):
         {
-            fout<<"<"<<name;
-            for(Properties::const_iterator oitr = properties.begin();
-                oitr != properties.end();
-                ++oitr)
-            {
-                fout<<" "<<oitr->first<<"=\"";
-                writeString(fout,oitr->second);
-                fout<<"\"";
-            }
+            fout<<indent<<"<"<<name;
+            writeProperties(fout);
             fout<<">"<<std::endl;
 
-            for(Children::const_iterator citr = children.begin();
-                citr != children.end();
-                ++citr)
-            {
-                (*citr)->write(fout);
-            }
-
-            fout<<"</"<<name<<">"<<std::endl;
+            writeChildren(fout, indent + "  ");
+
+            fout<<indent<<"</"<<name<<">"<<std::endl;
             return true;
         }
         case(COMMENT):
         {
-            fout<<"<!--"<<contents<<"-->"<<std::endl;
+            fout<<indent<<"<!--"<<contents<<"-->"<<std::endl;
             return true;
         }
         case(INFORMATION):
         {
-            fout<<"<?"<<contents<<"?>"<<std::endl;
+            fout<<indent<<"<?"<<contents<<"?>"<<std::endl;
             return true;
         }
@@ -465,2 +411,30 @@
     return true;
 }
+
+bool XmlNode::writeChildren(std::ostream& fout, const std::string& indent) const
+{
+    for(Children::const_iterator citr = children.begin();
+        citr != children.end();
+        ++citr)
+    {
+        if (!(*citr)->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<<" "<<oitr->first<<"=\"";
+        if (!writeString(fout,oitr->second))
+            return false;
+        fout<<"\"";
+    }
+
+    return true;
+}
