/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/sgx/filesystem/io/xml/fsioxmlnode.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/filesystem/filesystem.hpp"
#include "sgx/filesystem/io/xml/xml.hpp"

CSGXFile& 
operator<<(CSGXFile&File, const sgxXMLNode *pNode)
{
	int tab = 0;
	sgxString open_tag(sgxXMLBase::getTab(tab));

	// The <main> tag
	open_tag += "<";
	open_tag += pNode->m_Element.m_Name;

	sgxVector<sgxXMLAttribute>::const_iterator cit = pNode->m_Attribute.begin();
	for(;cit!=pNode->m_Attribute.end();++cit) {
		open_tag += " ";
		open_tag += (*cit).m_Name + " = \"" + (*cit).m_Value + "\"";
	}
	open_tag += ">";
	File.writeAsciiStringCR(open_tag);
	
	// The data inside it: generally null, if there are children
	// although some formats do not conform to this part of XML.
	File.writeAsciiStringCR(sgxXMLBase::getTab(tab) + pNode->m_Data);

	// The children tags
	sgxVector<sgxXMLNode *>::const_iterator cit_node = pNode->m_ChildNodes.begin();

	for(;cit_node!=pNode->m_ChildNodes.end();++cit_node) {
		File << (*cit_node);
	}

	// The </close> tag
	sgxString close_tag(sgxXMLBase::getTab(tab));
	close_tag += "</";
	close_tag += pNode->m_Element.m_Name;
	close_tag += ">";
	File.writeAsciiStringCR(close_tag);

	return File;
}