Index: trunk/src/lib/coord/p_node.cc
===================================================================
--- trunk/src/lib/coord/p_node.cc	(revision 5793)
+++ trunk/src/lib/coord/p_node.cc	(revision 5819)
@@ -334,4 +334,5 @@
   }
   this->relDirection = relDir;
+
   this->bRelCoorChanged = true;
 }
@@ -363,4 +364,5 @@
   *this->toDirection = relDirSoft;
   this->bias = bias;
+  this->bRelDirChanged = true;
 }
 
Index: trunk/src/lib/event/key_mapper.h
===================================================================
--- trunk/src/lib/event/key_mapper.h	(revision 5793)
+++ trunk/src/lib/event/key_mapper.h	(revision 5819)
@@ -29,5 +29,5 @@
   virtual ~KeyMapper();
 
-  void loadKeyBindings(const char* fileName = DEFAULT_CONFIG_FILE);
+  void loadKeyBindings(const char* fileName = NULL);
   void loadKeyBindings(IniParser* iniParser);
 
Index: trunk/src/lib/graphics/graphics_engine.cc
===================================================================
--- trunk/src/lib/graphics/graphics_engine.cc	(revision 5793)
+++ trunk/src/lib/graphics/graphics_engine.cc	(revision 5819)
@@ -30,4 +30,5 @@
 #include "text.h"
 
+#include "globals.h"
 
 #ifdef __WIN32__
Index: trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
===================================================================
--- trunk/src/lib/graphics/spatial_separation/quadtree_node.cc	(revision 5793)
+++ trunk/src/lib/graphics/spatial_separation/quadtree_node.cc	(revision 5819)
@@ -22,7 +22,7 @@
 #include "material.h"
 #include "abstract_model.h"
-#include "list.h"
-#include "vector.h"
 #include "debug.h"
+
+#include "util/list.h"
 
 using namespace std;
Index: trunk/src/lib/graphics/spatial_separation/quadtree_node.h
===================================================================
--- trunk/src/lib/graphics/spatial_separation/quadtree_node.h	(revision 5793)
+++ trunk/src/lib/graphics/spatial_separation/quadtree_node.h	(revision 5819)
@@ -16,5 +16,5 @@
 
 #include "base_object.h"
-#include "vector.h"
+
 #include "abstract_model.h"
 
Index: trunk/src/lib/sound/sound_engine.cc
===================================================================
--- trunk/src/lib/sound/sound_engine.cc	(revision 5793)
+++ trunk/src/lib/sound/sound_engine.cc	(revision 5819)
@@ -21,5 +21,4 @@
 #include "sound_engine.h"
 
-//#include <AL/alc.h> // maybe later
 #include "class_list.h"
 
@@ -208,4 +207,5 @@
 void SoundEngine::flushUnusedBuffers()
 {
+  /// FIXME
 /*  if(this->sourceList && this->bufferList)
   {
@@ -280,6 +280,19 @@
   }
 
-
-  alutInit(NULL, 0);
+  // INITIALIZING THE DEVICE:
+  ALCubyte deviceName[] =
+#ifdef __WIN32__
+      "native";
+#else
+      "'( ( devices '( native arts null ) ) )";
+#endif
+  //
+  this->device = alcOpenDevice(deviceName);
+
+  this->context = alcCreateContext(this->device, NULL);
+
+  alcMakeContextCurrent(this->context);
+
+
   if ((result = alGetError()) != AL_NO_ERROR)
     SoundEngine::PrintALErrorString(result);
Index: trunk/src/lib/sound/sound_engine.h
===================================================================
--- trunk/src/lib/sound/sound_engine.h	(revision 5793)
+++ trunk/src/lib/sound/sound_engine.h	(revision 5819)
@@ -68,9 +68,14 @@
     static SoundEngine*      singletonRef;             //!< Reference to this class
 
+    ALCdevice*               device;                   //!< the used audio-device.
+    ALCcontext*              context;                  //!< the context, currently in use.
+
     float                    musicVolume;              //!< the maximum volume of the music in % (0f,1f]
     float                    effectsVolume;            //!< the maximum volume of sound-effects in % (0f,1f]
     PNode*                   listener;                 //!< The listener of the Scene
+
     std::list<BaseObject*>*  bufferList;               //!< A list of buffers
     std::list<BaseObject*>*  sourceList;               //!< A list for all the sources in the scene.
+
 
 };
Index: trunk/src/lib/tinyxml/tinystr.cc
===================================================================
--- trunk/src/lib/tinyxml/tinystr.cc	(revision 5793)
+++ trunk/src/lib/tinyxml/tinystr.cc	(revision 5819)
@@ -3,15 +3,15 @@
 Original file by Yves Berquin.
 
-This software is provided 'as-is', without any express or implied 
-warranty. In no event will the authors be held liable for any 
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
 damages arising from the use of this software.
 
-Permission is granted to anyone to use this software for any 
-purpose, including commercial applications, and to alter it and 
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
 redistribute it freely, subject to the following restrictions:
 
-1. The origin of this software must not be misrepresented; you must 
-not claim that you wrote the original software. If you use this 
-software in a product, an acknowledgment in the product documentation 
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
 would be appreciated but is not required.
 
@@ -19,298 +19,95 @@
 must not be misrepresented as being the original software.
 
-3. This notice may not be removed or altered from any source 
+3. This notice may not be removed or altered from any source
 distribution.
 */
 
-#include "tinyxml.h"
+/*
+ * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005.
+ */
+
 
 #ifndef TIXML_USE_STL
 
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
 #include "tinystr.h"
 
-// TiXmlString constructor, based on a C string
-TiXmlString::TiXmlString (const char* instring)
+// Error value for find primitive
+const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1);
+
+// Null rep.
+TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' };
+
+
+void TiXmlString::reserve (size_type cap)
 {
-    size_t newlen;
-    char * newstring;
-
-    if (!instring)
-    {
-        allocated = 0;
-        cstring = NULL;
-        current_length = 0;
-        return;
-    }
-    newlen = strlen (instring) + 1;
-    newstring = new char [newlen];
-    memcpy (newstring, instring, newlen);
-    // strcpy (newstring, instring);
-    allocated = newlen;
-    cstring = newstring;
-    current_length = newlen - 1;
-}
-
-// TiXmlString copy constructor
-TiXmlString::TiXmlString (const TiXmlString& copy)
-{
-    size_t newlen;
-    char * newstring;
-
-	// Prevent copy to self!
-	if ( &copy == this )
-		return;
-
-    if (! copy . allocated)
-    {
-        allocated = 0;
-        cstring = NULL;
-        current_length = 0;
-        return;
-    }
-    newlen = copy . length () + 1;
-    newstring = new char [newlen];
-    // strcpy (newstring, copy . cstring);
-    memcpy (newstring, copy . cstring, newlen);
-    allocated = newlen;
-    cstring = newstring;
-    current_length = newlen - 1;
-}
-
-// TiXmlString = operator. Safe when assign own content
-void TiXmlString ::operator = (const char * content)
-{
-    size_t newlen;
-    char * newstring;
-
-    if (! content)
-    {
-        empty_it ();
-        return;
-    }
-    newlen = strlen (content) + 1;
-    newstring = new char [newlen];
-    // strcpy (newstring, content);
-    memcpy (newstring, content, newlen);
-    empty_it ();
-    allocated = newlen;
-    cstring = newstring;
-    current_length = newlen - 1;
-}
-
-// = operator. Safe when assign own content
-void TiXmlString ::operator = (const TiXmlString & copy)
-{
-    size_t newlen;
-    char * newstring;
-
-    if (! copy . length ())
-    {
-        empty_it ();
-        return;
-    }
-    newlen = copy . length () + 1;
-    newstring = new char [newlen];
-    // strcpy (newstring, copy . c_str ());
-    memcpy (newstring, copy . c_str (), newlen);
-    empty_it ();
-    allocated = newlen;
-    cstring = newstring;
-    current_length = newlen - 1;
+	if (cap > capacity())
+	{
+		TiXmlString tmp;
+		tmp.init(length(), cap);
+		memcpy(tmp.start(), data(), length());
+		swap(tmp);
+	}
 }
 
 
-// append a const char * to an existing TiXmlString
-void TiXmlString::append( const char* str, size_t len )
+TiXmlString& TiXmlString::assign(const char* str, size_type len)
 {
-    char * new_string;
-    size_t new_alloc, new_size, size_suffix;
-	
-	// don't use strlen - it can overrun the len passed in!
-	const char* p = str;
-	size_suffix = 0;
-
-	while ( *p && size_suffix < (unsigned)len )
+	size_type cap = capacity();
+	if (len > cap || cap > 3*(len + 8))
 	{
-		++p;
-		++size_suffix;
+		TiXmlString tmp;
+		tmp.init(len);
+		memcpy(tmp.start(), str, len);
+		swap(tmp);
 	}
-    if ( !size_suffix)
-        return;
-
-    new_size = length () + size_suffix + 1;
-    // check if we need to expand
-    if (new_size > allocated)
-    {
-        // compute new size
-        new_alloc = assign_new_size (new_size);
-
-        // allocate new buffer
-        new_string = new char [new_alloc];        
-        new_string [0] = 0;
-
-        // copy the previous allocated buffer into this one
-        if (allocated && cstring)
-            // strcpy (new_string, cstring);
-            memcpy (new_string, cstring, length ());
-
-        // append the suffix. It does exist, otherwize we wouldn't be expanding 
-        // strncat (new_string, str, len);
-        memcpy (new_string + length (), 
-                str,
-                size_suffix);
-
-        // return previsously allocated buffer if any
-        if (allocated && cstring)
-            delete [] cstring;
-
-        // update member variables
-        cstring = new_string;
-        allocated = new_alloc;
-    }
-    else
-    {
-        // we know we can safely append the new string
-        // strncat (cstring, str, len);
-        memcpy (cstring + length (), 
-                str,
-                size_suffix);
-    }
-    current_length = new_size - 1;
-    cstring [current_length] = 0;
+	else
+	{
+		memmove(start(), str, len);
+		set_size(len);
+	}
+	return *this;
 }
 
 
-// append a const char * to an existing TiXmlString
-void TiXmlString::append( const char * suffix )
+TiXmlString& TiXmlString::append(const char* str, size_type len)
 {
-    char * new_string;
-    size_t new_alloc, new_size;
-
-    new_size = length () + strlen (suffix) + 1;
-    // check if we need to expand
-    if (new_size > allocated)
-    {
-        // compute new size
-        new_alloc = assign_new_size (new_size);
-
-        // allocate new buffer
-        new_string = new char [new_alloc];        
-        new_string [0] = 0;
-
-        // copy the previous allocated buffer into this one
-        if (allocated && cstring)
-            memcpy (new_string, cstring, 1 + length ());
-            // strcpy (new_string, cstring);
-
-        // append the suffix. It does exist, otherwize we wouldn't be expanding 
-        // strcat (new_string, suffix);
-        memcpy (new_string + length (), 
-                suffix,
-                strlen (suffix) + 1);
-
-        // return previsously allocated buffer if any
-        if (allocated && cstring)
-            delete [] cstring;
-
-        // update member variables
-        cstring = new_string;
-        allocated = new_alloc;
-    }
-    else
-    {
-        // we know we can safely append the new string
-        // strcat (cstring, suffix);
-        memcpy (cstring + length (), 
-                suffix, 
-                strlen (suffix) + 1);
-    }
-    current_length = new_size - 1;
-}
-
-// Check for TiXmlString equuivalence
-//bool TiXmlString::operator == (const TiXmlString & compare) const
-//{
-//    return (! strcmp (c_str (), compare . c_str ()));
-//}
-
-//unsigned TiXmlString::length () const
-//{
-//    if (allocated)
-//        // return strlen (cstring);
-//        return current_length;
-//    return 0;
-//}
-
-
-unsigned TiXmlString::find (char tofind, unsigned offset) const
-{
-    char * lookup;
-
-    if (offset >= length ())
-        return (unsigned) notfound;
-    for (lookup = cstring + offset; * lookup; lookup++)
-        if (* lookup == tofind)
-            return (unsigned)(lookup - cstring);
-    return (unsigned) notfound;
+	size_type newsize = length() + len;
+	if (newsize > capacity())
+	{
+		reserve (newsize + capacity());
+	}
+	memmove(finish(), str, len);
+	set_size(newsize);
+	return *this;
 }
 
 
-bool TiXmlString::operator == (const TiXmlString & compare) const
+TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
 {
-	if ( allocated && compare.allocated )
-	{
-		assert( cstring );
-		assert( compare.cstring );
-		return ( strcmp( cstring, compare.cstring ) == 0 );
- 	}
-	else if ( length() == 0 && compare.length() == 0 )
-	{
-		return true;
-	}
-	return false;
+	TiXmlString tmp;
+	tmp.reserve(a.length() + b.length());
+	tmp += a;
+	tmp += b;
+	return tmp;
 }
 
-
-bool TiXmlString::operator == (const char* compare) const
+TiXmlString operator + (const TiXmlString & a, const char* b)
 {
-	if ( allocated && compare && *compare )
-	{
-		assert( cstring );
-		return ( strcmp( cstring, compare ) == 0 );
- 	}
-	else if ( length() == 0 && (!compare || !*compare ) )	// this is a little dubious, but try to duplicate behavior in other operator==
-	{
-		return true;
-	}
-	return false;	
+	TiXmlString tmp;
+	TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
+	tmp.reserve(a.length() + b_len);
+	tmp += a;
+	tmp.append(b, b_len);
+	return tmp;
 }
 
-
-bool TiXmlString::operator < (const TiXmlString & compare) const
+TiXmlString operator + (const char* a, const TiXmlString & b)
 {
-	if ( allocated && compare.allocated )
-	{
-		assert( cstring );
-		assert( compare.cstring );
-		return ( strcmp( cstring, compare.cstring ) > 0 );
- 	}
-	return false;
-}
-
-
-bool TiXmlString::operator > (const TiXmlString & compare) const
-{
-	if ( allocated && compare.allocated )
-	{
-		assert( cstring );
-		assert( compare.cstring );
-		return ( strcmp( cstring, compare.cstring ) < 0 );
- 	}
-	return false;
+	TiXmlString tmp;
+	TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
+	tmp.reserve(a_len + b.length());
+	tmp.append(a, a_len);
+	tmp += b;
+	return tmp;
 }
 
Index: trunk/src/lib/tinyxml/tinystr.h
===================================================================
--- trunk/src/lib/tinyxml/tinystr.h	(revision 5793)
+++ trunk/src/lib/tinyxml/tinystr.h	(revision 5819)
@@ -3,15 +3,15 @@
 Original file by Yves Berquin.
 
-This software is provided 'as-is', without any express or implied 
-warranty. In no event will the authors be held liable for any 
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
 damages arising from the use of this software.
 
-Permission is granted to anyone to use this software for any 
-purpose, including commercial applications, and to alter it and 
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
 redistribute it freely, subject to the following restrictions:
 
-1. The origin of this software must not be misrepresented; you must 
-not claim that you wrote the original software. If you use this 
-software in a product, an acknowledgment in the product documentation 
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
 would be appreciated but is not required.
 
@@ -19,10 +19,19 @@
 must not be misrepresented as being the original software.
 
-3. This notice may not be removed or altered from any source 
+3. This notice may not be removed or altered from any source
 distribution.
 */
 
-#include "tinyxml.h"
-
+/*
+ * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
+ *
+ * - completely rewritten. compact, clean, and fast implementation.
+ * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
+ * - fixed reserve() to work as per specification.
+ * - fixed buggy compares operator==(), operator<(), and operator>()
+ * - fixed operator+=() to take a const ref argument, following spec.
+ * - added "copy" constructor with length, and most compare operators.
+ * - added swap(), clear(), size(), capacity(), operator+().
+ */
 
 #ifndef TIXML_USE_STL
@@ -31,13 +40,9 @@
 #define TIXML_STRING_INCLUDED
 
-#ifdef _MSC_VER
-#pragma warning( disable : 4530 )
-#pragma warning( disable : 4786 )
-#endif
-
 #include <assert.h>
+#include <string.h>
 
 /*
-   TiXmlString is an emulation of the std::string template.
+   TiXmlString is an emulation of a subset of the std::string template.
    Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
    Only the member functions relevant to the TinyXML project have been implemented.
@@ -48,175 +53,229 @@
 {
   public :
-    // TiXmlString constructor, based on a string, mark explicit to force
-	// us to find unnecessary casting.
-    explicit TiXmlString (const char * instring);
-
-    // TiXmlString empty constructor
-    TiXmlString ()
-    {
-        allocated = 0;
-        cstring = NULL;
-        current_length = 0;
-    }
-
-    // TiXmlString copy constructor
-    explicit TiXmlString (const TiXmlString& copy);
-
-    // TiXmlString destructor
-    ~ TiXmlString ()
-    {
-        empty_it ();
-    }
-
-    // Convert a TiXmlString into a classical char *
-    const char * c_str () const
-    {
-        if (allocated)
-            return cstring;
-        return "";
-    }
-
-    // Return the length of a TiXmlString
-    size_t length () const
-	{
-		return ( allocated ) ? current_length : 0;
-	}
-
-    // TiXmlString = operator
-    void operator = (const char * content);
-
-    // = operator
-    void operator = (const TiXmlString & copy);
-
-    // += operator. Maps to append
-    TiXmlString& operator += (const char * suffix)
-    {
-        append (suffix);
-		return *this;
-    }
-
-    // += operator. Maps to append
-    TiXmlString& operator += (char single)
-    {
-        append (single);
-		return *this;
-    }
-
-    // += operator. Maps to append
-    TiXmlString& operator += (TiXmlString & suffix)
-    {
-        append (suffix);
-		return *this;
-    }
-    bool operator == (const TiXmlString & compare) const;
-    bool operator == (const char* compare) const;
-    bool operator < (const TiXmlString & compare) const;
-    bool operator > (const TiXmlString & compare) const;
-
-    // Checks if a TiXmlString is empty
-    bool empty () const
-    {
-        return length () ? false : true;
-    }
-
-    // single char extraction
-    const char& at (unsigned index) const
-    {
-        assert( index < length ());
-        return cstring [index];
-    }
-
-    // find a char in a string. Return TiXmlString::notfound if not found
-    unsigned find (char lookup) const
-    {
-        return find (lookup, 0);
-    }
-
-    // find a char in a string from an offset. Return TiXmlString::notfound if not found
-    unsigned find (char tofind, unsigned offset) const;
-
-    /*	Function to reserve a big amount of data when we know we'll need it. Be aware that this
-		function clears the content of the TiXmlString if any exists.
-    */
-    void reserve (unsigned size)
-    {
-        empty_it ();
-        if (size)
-        {
-            allocated = size;
-            cstring = new char [size];
-            cstring [0] = 0;
-            current_length = 0;
-        }
-    }
-
-    // [] operator 
-    char& operator [] (unsigned index) const
-    {
-        assert( index < length ());
-        return cstring [index];
-    }
-
-    // Error value for find primitive 
-    enum {	notfound = 0xffffffff,
-            npos = notfound };
-
-    void append (const char *str, size_t len );
-
-  protected :
-
-    // The base string
-    char * cstring;
-    // Number of chars allocated
-    size_t allocated;
-    // Current string size
-    size_t current_length;
-
-    // New size computation. It is simplistic right now : it returns twice the amount
-    // we need
-    size_t assign_new_size (size_t minimum_to_allocate)
-    {
-        return minimum_to_allocate * 2;
-    }
-
-    // Internal function that clears the content of a TiXmlString
-    void empty_it ()
-    {
-        if (cstring)
-            delete [] cstring;
-        cstring = NULL;
-        allocated = 0;
-        current_length = 0;
-    }
-
-    void append (const char *suffix );
-
-    // append function for another TiXmlString
-    void append (const TiXmlString & suffix)
-    {
-        append (suffix . c_str ());
-    }
-
-    // append for a single char.
-    void append (char single)
-    {
-        if ( cstring && current_length < (allocated-1) )
+	// The size type used
+  	typedef unsigned int size_type;
+
+	// Error value for find primitive
+	static const size_type npos; // = -1;
+
+
+	// TiXmlString empty constructor
+	TiXmlString () : rep_(&nullrep_)
+	{
+	}
+
+	// TiXmlString copy constructor
+	TiXmlString (const TiXmlString & copy)
+	{
+		init(copy.length());
+		memcpy(start(), copy.data(), length());
+	}
+
+	// TiXmlString constructor, based on a string
+	TiXmlString (const char * copy)
+	{
+		init( static_cast<size_type>( strlen(copy) ));
+		memcpy(start(), copy, length());
+	}
+
+	// TiXmlString constructor, based on a string
+	TiXmlString (const char * str, size_type len)
+	{
+		init(len);
+		memcpy(start(), str, len);
+	}
+
+	// TiXmlString destructor
+	~TiXmlString ()
+	{
+		quit();
+	}
+
+	// = operator
+	TiXmlString& operator = (const char * copy)
+	{
+		return assign( copy, (size_type)strlen(copy));
+	}
+
+	// = operator
+	TiXmlString& operator = (const TiXmlString & copy)
+	{
+		return assign(copy.start(), copy.length());
+	}
+
+
+	// += operator. Maps to append
+	TiXmlString& operator += (const char * suffix)
+	{
+		return append(suffix, static_cast<size_type>( strlen(suffix) ));
+	}
+
+	// += operator. Maps to append
+	TiXmlString& operator += (char single)
+	{
+		return append(&single, 1);
+	}
+
+	// += operator. Maps to append
+	TiXmlString& operator += (const TiXmlString & suffix)
+	{
+		return append(suffix.data(), suffix.length());
+	}
+
+
+	// Convert a TiXmlString into a null-terminated char *
+	const char * c_str () const { return rep_->str; }
+
+	// Convert a TiXmlString into a char * (need not be null terminated).
+	const char * data () const { return rep_->str; }
+
+	// Return the length of a TiXmlString
+	size_type length () const { return rep_->size; }
+
+	// Alias for length()
+	size_type size () const { return rep_->size; }
+
+	// Checks if a TiXmlString is empty
+	bool empty () const { return rep_->size == 0; }
+
+	// Return capacity of string
+	size_type capacity () const { return rep_->capacity; }
+
+
+	// single char extraction
+	const char& at (size_type index) const
+	{
+		assert( index < length() );
+		return rep_->str[ index ];
+	}
+
+	// [] operator
+	char& operator [] (size_type index) const
+	{
+		assert( index < length() );
+		return rep_->str[ index ];
+	}
+
+	// find a char in a string. Return TiXmlString::npos if not found
+	size_type find (char lookup) const
+	{
+		return find(lookup, 0);
+	}
+
+	// find a char in a string from an offset. Return TiXmlString::npos if not found
+	size_type find (char tofind, size_type offset) const
+	{
+		if (offset >= length()) return npos;
+
+		for (const char* p = c_str() + offset; *p != '\0'; ++p)
 		{
-			cstring[ current_length ] = single;
-			++current_length;
-			cstring[ current_length ] = 0;
+		   if (*p == tofind) return static_cast< size_type >( p - c_str() );
+		}
+		return npos;
+	}
+
+	void clear ()
+	{
+		//Lee:
+		//The original was just too strange, though correct:
+		//	TiXmlString().swap(*this);
+		//Instead use the quit & re-init:
+		quit();
+		init(0,0);
+	}
+
+	/*	Function to reserve a big amount of data when we know we'll need it. Be aware that this
+		function DOES NOT clear the content of the TiXmlString if any exists.
+	*/
+	void reserve (size_type cap);
+
+	TiXmlString& assign (const char* str, size_type len);
+
+	TiXmlString& append (const char* str, size_type len);
+
+	void swap (TiXmlString& other)
+	{
+		Rep* r = rep_;
+		rep_ = other.rep_;
+		other.rep_ = r;
+	}
+
+  private:
+
+	void init(size_type sz) { init(sz, sz); }
+	void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
+	char* start() const { return rep_->str; }
+	char* finish() const { return rep_->str + rep_->size; }
+
+	struct Rep
+	{
+		size_type size, capacity;
+		char str[1];
+	};
+
+	void init(size_type sz, size_type cap)
+	{
+		if (cap)
+		{
+			// Lee: the original form:
+			//	rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
+			// doesn't work in some cases of new being overloaded. Switching
+			// to the normal allocation, although use an 'int' for systems
+			// that are overly picky about structure alignment.
+			const size_type bytesNeeded = sizeof(Rep) + cap;
+			const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); 
+			rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
+
+			rep_->str[ rep_->size = sz ] = '\0';
+			rep_->capacity = cap;
 		}
 		else
 		{
-			char smallstr [2];
-			smallstr [0] = single;
-			smallstr [1] = 0;
-			append (smallstr);
+			rep_ = &nullrep_;
 		}
-    }
+	}
+
+	void quit()
+	{
+		if (rep_ != &nullrep_)
+		{
+			// The rep_ is really an array of ints. (see the allocator, above).
+			// Cast it back before delete, so the compiler won't incorrectly call destructors.
+			delete [] ( reinterpret_cast<int*>( rep_ ) );
+		}
+	}
+
+	Rep * rep_;
+	static Rep nullrep_;
 
 } ;
 
-/* 
+
+inline bool operator == (const TiXmlString & a, const TiXmlString & b)
+{
+	return    ( a.length() == b.length() )				// optimization on some platforms
+	       && ( strcmp(a.c_str(), b.c_str()) == 0 );	// actual compare
+}
+inline bool operator < (const TiXmlString & a, const TiXmlString & b)
+{
+	return strcmp(a.c_str(), b.c_str()) < 0;
+}
+
+inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
+inline bool operator >  (const TiXmlString & a, const TiXmlString & b) { return b < a; }
+inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
+inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
+
+inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
+inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
+inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
+inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
+
+TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
+TiXmlString operator + (const TiXmlString & a, const char* b);
+TiXmlString operator + (const char* a, const TiXmlString & b);
+
+
+/*
    TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
    Only the operators that we need for TinyXML have been developped.
@@ -225,25 +284,20 @@
 {
 public :
-    TiXmlOutStream () : TiXmlString () {}
-
-    // TiXmlOutStream << operator. Maps to TiXmlString::append
-    TiXmlOutStream & operator << (const char * in)
-    {
-        append (in);
-        return (* this);
-    }
-
-    // TiXmlOutStream << operator. Maps to TiXmlString::append
-    TiXmlOutStream & operator << (const TiXmlString & in)
-    {
-        append (in . c_str ());
-        return (* this);
-    }
+
+	// TiXmlOutStream << operator.
+	TiXmlOutStream & operator << (const TiXmlString & in)
+	{
+		*this += in;
+		return *this;
+	}
+
+	// TiXmlOutStream << operator.
+	TiXmlOutStream & operator << (const char * in)
+	{
+		*this += in;
+		return *this;
+	}
+
 } ;
-
-#ifdef _MSC_VER
-#pragma warning( default : 4530 )
-#pragma warning( default : 4786 )
-#endif
 
 #endif	// TIXML_STRING_INCLUDED
Index: trunk/src/lib/tinyxml/tinyxml.cc
===================================================================
--- trunk/src/lib/tinyxml/tinyxml.cc	(revision 5793)
+++ trunk/src/lib/tinyxml/tinyxml.cc	(revision 5819)
@@ -101,5 +101,11 @@
 			// Below 32 is symbolic.
 			char buf[ 32 ];
-			sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
+			
+			#if defined(TIXML_SNPRINTF)		
+				TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) );
+			#else
+				sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
+			#endif		
+
 			//*ME:	warning C4267: convert 'size_t' to 'int'
 			//*ME:	Int-Cast to make compiler happy ...
@@ -319,5 +325,5 @@
 	for ( node = firstChild; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -331,5 +337,5 @@
 	for ( node = firstChild; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -343,5 +349,5 @@
 	for ( node = lastChild; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -354,5 +360,5 @@
 	for ( node = lastChild; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -417,5 +423,5 @@
 	for ( node = next; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -428,5 +434,5 @@
 	for ( node = next; node; node = node->next )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -439,5 +445,5 @@
 	for ( node = prev; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -450,5 +456,5 @@
 	for ( node = prev; node; node = node->prev )
 	{
-		if ( node->SValue() == _value )
+		if ( strcmp( node->Value(), _value ) == 0 )
 			return node;
 	}
@@ -716,5 +722,9 @@
 {	
 	char buf[64];
-	sprintf( buf, "%d", val );
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF( buf, sizeof(buf), "%d", val );
+	#else
+		sprintf( buf, "%d", val );
+	#endif
 	SetAttribute( name, buf );
 }
@@ -724,5 +734,9 @@
 {	
 	char buf[256];
-	sprintf( buf, "%f", val );
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF( buf, sizeof(buf), "%f", val );
+	#else
+		sprintf( buf, "%f", val );
+	#endif
 	SetAttribute( name, buf );
 }
@@ -866,7 +880,21 @@
 
 
+const char* TiXmlElement::GetText() const
+{
+	const TiXmlNode* child = this->FirstChild();
+	if ( child ) {
+		const TiXmlText* childText = child->ToText();
+		if ( childText ) {
+			return childText->Value();
+		}
+	}
+	return 0;
+}
+
+
 TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT )
 {
 	tabsize = 4;
+	useMicrosoftBOM = false;
 	ClearError();
 }
@@ -875,4 +903,5 @@
 {
 	tabsize = 4;
+	useMicrosoftBOM = false;
 	value = documentName;
 	ClearError();
@@ -884,4 +913,5 @@
 {
 	tabsize = 4;
+	useMicrosoftBOM = false;
     value = documentName;
 	ClearError();
@@ -942,5 +972,6 @@
 	value = filename;
 
-	FILE* file = fopen( value.c_str (), "r" );
+	// reading in binary mode so that tinyxml can normalize the EOL
+	FILE* file = fopen( value.c_str (), "rb" );	
 
 	if ( file )
@@ -964,12 +995,81 @@
 		data.reserve( length );
 
-		const int BUF_SIZE = 2048;
-		char buf[BUF_SIZE];
-
-		while( fgets( buf, BUF_SIZE, file ) )
+		// Subtle bug here. TinyXml did use fgets. But from the XML spec:
+		// 2.11 End-of-Line Handling
+		// <snip>
+		// <quote>
+		// ...the XML processor MUST behave as if it normalized all line breaks in external 
+		// parsed entities (including the document entity) on input, before parsing, by translating 
+		// both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 
+		// a single #xA character.
+		// </quote>
+		//
+		// It is not clear fgets does that, and certainly isn't clear it works cross platform. 
+		// Generally, you expect fgets to translate from the convention of the OS to the c/unix
+		// convention, and not work generally.
+
+		/*
+		while( fgets( buf, sizeof(buf), file ) )
 		{
 			data += buf;
 		}
+		*/
+
+		char* buf = new char[ length+1 ];
+		buf[0] = 0;
+
+		if ( fread( buf, length, 1, file ) != 1 ) {
+		//if ( fread( buf, 1, length, file ) != (size_t)length ) {
+			SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
+			fclose( file );
+			return false;
+		}
 		fclose( file );
+
+		const char* lastPos = buf;
+		const char* p = buf;
+
+		buf[length] = 0;
+		while( *p ) {
+			assert( p < (buf+length) );
+			if ( *p == 0xa ) {
+				// Newline character. No special rules for this. Append all the characters
+				// since the last string, and include the newline.
+				data.append( lastPos, p-lastPos+1 );	// append, include the newline
+				++p;									// move past the newline
+				lastPos = p;							// and point to the new buffer (may be 0)
+				assert( p <= (buf+length) );
+			}
+			else if ( *p == 0xd ) {
+				// Carriage return. Append what we have so far, then
+				// handle moving forward in the buffer.
+				if ( (p-lastPos) > 0 ) {
+					data.append( lastPos, p-lastPos );	// do not add the CR
+				}
+				data += (char)0xa;						// a proper newline
+
+				if ( *(p+1) == 0xa ) {
+					// Carriage return - new line sequence
+					p += 2;
+					lastPos = p;
+					assert( p <= (buf+length) );
+				}
+				else {
+					// it was followed by something else...that is presumably characters again.
+					++p;
+					lastPos = p;
+					assert( p <= (buf+length) );
+				}
+			}
+			else {
+				++p;
+			}
+		}
+		// Handle any left over characters.
+		if ( p-lastPos ) {
+			data.append( lastPos, p-lastPos );
+		}		
+		delete [] buf;
+		buf = 0;
 
 		Parse( data.c_str(), 0, encoding );
@@ -990,4 +1090,14 @@
 	if ( fp )
 	{
+		if ( useMicrosoftBOM ) 
+		{
+			const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
+			const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
+			const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
+
+			fputc( TIXML_UTF_LEAD_0, fp );
+			fputc( TIXML_UTF_LEAD_1, fp );
+			fputc( TIXML_UTF_LEAD_2, fp );
+		}
 		Print( fp, 0 );
 		fclose( fp );
@@ -1135,5 +1245,9 @@
 {
 	char buf [64];
-	sprintf (buf, "%d", _value);
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
+	#else
+		sprintf (buf, "%d", _value);
+	#endif
 	SetValue (buf);
 }
@@ -1142,14 +1256,18 @@
 {
 	char buf [256];
-	sprintf (buf, "%lf", _value);
+	#if defined(TIXML_SNPRINTF)		
+		TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value);
+	#else
+		sprintf (buf, "%lf", _value);
+	#endif
 	SetValue (buf);
 }
 
-const int TiXmlAttribute::IntValue() const
+int TiXmlAttribute::IntValue() const
 {
 	return atoi (value.c_str ());
 }
 
-const double  TiXmlAttribute::DoubleValue() const
+double  TiXmlAttribute::DoubleValue() const
 {
 	return atof (value.c_str ());
@@ -1206,9 +1324,23 @@
 
 
-void TiXmlText::Print( FILE* cfile, int /*depth*/ ) const
-{
-	TIXML_STRING buffer;
-	PutString( value, &buffer );
-	fprintf( cfile, "%s", buffer.c_str() );
+void TiXmlText::Print( FILE* cfile, int depth ) const
+{
+	if ( cdata )
+	{
+		int i;
+		fprintf( cfile, "\n" );
+		for ( i=0; i<depth; i++ ) {
+			fprintf( cfile, "    " );
+		}
+		fprintf( cfile, "<![CDATA[" );
+		fprintf( cfile, "%s", value.c_str() );	// unformatted output
+		fprintf( cfile, "]]>\n" );
+	}
+	else
+	{
+		TIXML_STRING buffer;
+		PutString( value, &buffer );
+		fprintf( cfile, "%s", buffer.c_str() );
+	}
 }
 
@@ -1216,5 +1348,12 @@
 void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const
 {
-	PutString( value, stream );
+	if ( cdata )
+	{
+		(*stream) << "<![CDATA[" << value << "]]>";
+	}
+	else
+	{
+		PutString( value, stream );
+	}
 }
 
@@ -1223,4 +1362,5 @@
 {
 	TiXmlNode::CopyTo( target );
+	target->cdata = cdata;
 }
 
Index: trunk/src/lib/tinyxml/tinyxml.h
===================================================================
--- trunk/src/lib/tinyxml/tinyxml.h	(revision 5793)
+++ trunk/src/lib/tinyxml/tinyxml.h	(revision 5819)
@@ -28,4 +28,5 @@
 
 #ifdef _MSC_VER
+#pragma warning( push )
 #pragma warning( disable : 4530 )
 #pragma warning( disable : 4786 )
@@ -62,4 +63,24 @@
 #endif
 
+// Deprecated library function hell. Compilers want to use the
+// new safe versions. This probably doesn't fully address the problem,
+// but it gets closer. There are too many compilers for me to fully
+// test. If you get compilation troubles, undefine TIXML_SAFE
+
+#define TIXML_SAFE		// TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
+#ifdef TIXML_SAFE
+	#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
+		// Microsoft visual studio, version 6 and higher.
+		//#pragma message( "Using _sn* functions." )
+		#define TIXML_SNPRINTF _snprintf
+		#define TIXML_SNSCANF  _snscanf
+	#elif defined(__GNUC__) && (__GNUC__ >= 3 )
+		// GCC version 3 and higher.s
+		//#warning( "Using sn* functions." )
+		#define TIXML_SNPRINTF snprintf
+		#define TIXML_SNSCANF  snscanf
+	#endif
+#endif	
+
 class TiXmlDocument;
 class TiXmlElement;
@@ -72,6 +93,6 @@
 
 const int TIXML_MAJOR_VERSION = 2;
-const int TIXML_MINOR_VERSION = 3;
-const int TIXML_PATCH_VERSION = 4;
+const int TIXML_MINOR_VERSION = 4;
+const int TIXML_PATCH_VERSION = 2;
 
 /*	Internal structure for tracking location of items 
@@ -206,4 +227,5 @@
 		TIXML_ERROR_DOCUMENT_EMPTY,
 		TIXML_ERROR_EMBEDDED_NULL,
+		TIXML_ERROR_PARSING_CDATA,
 
 		TIXML_ERROR_STRING_COUNT
@@ -278,5 +300,9 @@
 		else if ( *length )
 		{
-			strncpy( _value, p, *length );
+			//strncpy( _value, p, *length );	// lots of compilers don't like this function (unsafe),
+												// and the null terminator isn't needed
+			for( int i=0; p[i] && i<*length; ++i ) {
+				_value[i] = p[i];
+			}
 			return p + (*length);
 		}
@@ -296,5 +322,5 @@
 	// Return true if the next characters in the stream are any of the endTag sequences.
 	// Ignore case only works for english, and should only be relied on when comparing
-	// to Engilish words: StringEqual( p, "version", true ) is fine.
+	// to English words: StringEqual( p, "version", true ) is fine.
 	static bool StringEqual(	const char* p,
 								const char* endTag,
@@ -421,5 +447,13 @@
 		The subclasses will wrap this function.
 	*/
-	const char * Value() const { return value.c_str (); }
+	const char *Value() const { return value.c_str (); }
+
+    #ifdef TIXML_USE_STL
+	/** Return Value() as a std::string. If you only use STL,
+	    this is more efficient than calling Value().
+		Only available in STL mode.
+	*/
+	const std::string& ValueStr() const { return value; }
+	#endif
 
 	/** Changes the value of the node. Defined as:
@@ -589,5 +623,5 @@
 								UNKNOWN, TEXT, and DECLARATION.
 	*/
-	virtual int Type() const	{ return type; }
+	int Type() const	{ return type; }
 
 	/** Return a pointer to the Document this node lives in.
@@ -633,7 +667,4 @@
 	// Figure out what is at *p, and parse it. Returns null if it is not an xml node.
 	TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
-
-	// Internal Value function returning a TIXML_STRING
-	const TIXML_STRING& SValue() const	{ return value ; }
 
 	TiXmlNode*		parent;
@@ -695,6 +726,6 @@
 	const char*		Name()  const		{ return name.c_str (); }		///< Return the name of this attribute.
 	const char*		Value() const		{ return value.c_str (); }		///< Return the value of this attribute.
-	const int       IntValue() const;									///< Return the value of this attribute, converted to an integer.
-	const double	DoubleValue() const;								///< Return the value of this attribute, converted to a double.
+	int				IntValue() const;									///< Return the value of this attribute, converted to an integer.
+	double			DoubleValue() const;								///< Return the value of this attribute, converted to a double.
 
 	/** QueryIntValue examines the value string. It is an alternative to the
@@ -707,13 +738,13 @@
 		which is the opposite of almost all other TinyXml calls.
 	*/
-	int QueryIntValue( int* value ) const;
+	int QueryIntValue( int* _value ) const;
 	/// QueryDoubleValue examines the value string. See QueryIntValue().
-	int QueryDoubleValue( double* value ) const;
+	int QueryDoubleValue( double* _value ) const;
 
 	void SetName( const char* _name )	{ name = _name; }				///< Set the name of this attribute.
 	void SetValue( const char* _value )	{ value = _value; }				///< Set the value.
 
-	void SetIntValue( int value );										///< Set the value from an integer.
-	void SetDoubleValue( double value );								///< Set the value from a double.
+	void SetIntValue( int _value );										///< Set the value from an integer.
+	void SetDoubleValue( double _value );								///< Set the value from a double.
 
     #ifdef TIXML_USE_STL
@@ -856,12 +887,14 @@
 		does not exist, then TIXML_NO_ATTRIBUTE is returned.
 	*/	
-	int QueryIntAttribute( const char* name, int* value ) const;
+	int QueryIntAttribute( const char* name, int* _value ) const;
 	/// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
-	int QueryDoubleAttribute( const char* name, double* value ) const;
+	int QueryDoubleAttribute( const char* name, double* _value ) const;
 	/// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
-	int QueryDoubleAttribute( const char* name, float* value ) const {
+	int QueryFloatAttribute( const char* name, float* _value ) const {
 		double d;
 		int result = QueryDoubleAttribute( name, &d );
-		*value = (float)d;
+		if ( result == TIXML_SUCCESS ) {
+			*_value = (float)d;
+		}
 		return result;
 	}
@@ -870,5 +903,5 @@
 		will be created if it does not exist, or changed if it does.
 	*/
-	void SetAttribute( const char* name, const char * value );
+	void SetAttribute( const char* name, const char * _value );
 
     #ifdef TIXML_USE_STL
@@ -876,6 +909,6 @@
 	const char* Attribute( const std::string& name, int* i ) const		{ return Attribute( name.c_str(), i ); }
 	const char* Attribute( const std::string& name, double* d ) const	{ return Attribute( name.c_str(), d ); }
-	int QueryIntAttribute( const std::string& name, int* value ) const	{ return QueryIntAttribute( name.c_str(), value ); }
-	int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
+	int QueryIntAttribute( const std::string& name, int* _value ) const	{ return QueryIntAttribute( name.c_str(), _value ); }
+	int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
 
 	/// STL std::string form.
@@ -918,4 +951,38 @@
 	TiXmlAttribute* LastAttribute()					{ return attributeSet.Last(); }
 
+	/** Convenience function for easy access to the text inside an element. Although easy
+		and concise, GetText() is limited compared to getting the TiXmlText child
+		and accessing it directly.
+	
+		If the first child of 'this' is a TiXmlText, the GetText()
+		returns the character string of the Text node, else null is returned.
+
+		This is a convenient method for getting the text of simple contained text:
+		@verbatim
+		<foo>This is text</foo>
+		const char* str = fooElement->GetText();
+		@endverbatim
+
+		'str' will be a pointer to "This is text". 
+		
+		Note that this function can be misleading. If the element foo was created from
+		this XML:
+		@verbatim
+		<foo><b>This is text</b></foo> 
+		@endverbatim
+
+		then the value of str would be null. The first child node isn't a text node, it is
+		another element. From this XML:
+		@verbatim
+		<foo>This is <b>text</b></foo> 
+		@endverbatim
+		GetText() will return "This is ".
+
+		WARNING: GetText() accesses a child node - don't become confused with the 
+				 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 
+				 safe type casts on the referenced node.
+	*/
+	const char* GetText() const;
+
 	/// Creates a new Element and returns it - the returned element is a copy.
 	virtual TiXmlNode* Clone() const;
@@ -987,5 +1054,8 @@
 
 
-/** XML text. Contained in an element.
+/** XML text. A text node can have 2 ways to output the next. "normal" output 
+	and CDATA. It will default to the mode it was parsed from the XML file and
+	you generally want to leave it alone, but you can change the output mode with 
+	SetCDATA() and query it with CDATA().
 */
 class TiXmlText : public TiXmlNode
@@ -993,8 +1063,12 @@
 	friend class TiXmlElement;
 public:
-	/// Constructor.
-	TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
+	/** Constructor for text element. By default, it is treated as 
+		normal, encoded text. If you want it be output as a CDATA text
+		element, set the parameter _cdata to 'true'
+	*/
+	TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
 	{
 		SetValue( initValue );
+		cdata = false;
 	}
 	virtual ~TiXmlText() {}
@@ -1005,4 +1079,5 @@
 	{
 		SetValue( initValue );
+		cdata = false;
 	}
 	#endif
@@ -1013,4 +1088,9 @@
 	/// Write this text object to a FILE stream.
 	virtual void Print( FILE* cfile, int depth ) const;
+
+	/// Queries whether this represents text using a CDATA section.
+	bool CDATA()					{ return cdata; }
+	/// Turns on or off a CDATA representation of text.
+	void SetCDATA( bool _cdata )	{ cdata = _cdata; }
 
 	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
@@ -1029,4 +1109,5 @@
 
 private:
+	bool cdata;			// true if this should be input and output as a CDATA style text element
 };
 
@@ -1207,5 +1288,5 @@
 		prefer the ErrorId, this function will fetch it.
 	*/
-	const int ErrorId()	const				{ return errorId; }
+	int ErrorId()	const				{ return errorId; }
 
 	/** Returns the location (if known) of the error. The first column is column 1, 
@@ -1219,5 +1300,9 @@
 	int ErrorCol()	{ return errorLocation.col+1; }	///< The column where the error occured. See ErrorRow()
 
-	/** By calling this method, with a tab size
+	/** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
+		to report the correct values for row and column. It does not change the output
+		or input in any way.
+		
+		By calling this method, with a tab size
 		greater than 0, the row and column of each node and attribute is stored
 		when the file is loaded. Very useful for tracking the DOM back in to
@@ -1277,4 +1362,5 @@
 	int tabsize;
 	TiXmlCursor errorLocation;
+	bool useMicrosoftBOM;		// the UTF-8 BOM were found when read. Note this, and try to write.
 };
 
@@ -1364,5 +1450,5 @@
 public:
 	/// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
-	TiXmlHandle( TiXmlNode* node )					{ this->node = node; }
+	TiXmlHandle( TiXmlNode* _node )					{ this->node = _node; }
 	/// Copy constructor
 	TiXmlHandle( const TiXmlHandle& ref )			{ this->node = ref.node; }
@@ -1419,6 +1505,5 @@
 
 #ifdef _MSC_VER
-#pragma warning( default : 4530 )
-#pragma warning( default : 4786 )
+#pragma warning( pop )
 #endif
 
Index: trunk/src/lib/tinyxml/tinyxmlerror.cc
===================================================================
--- trunk/src/lib/tinyxml/tinyxmlerror.cc	(revision 5793)
+++ trunk/src/lib/tinyxml/tinyxmlerror.cc	(revision 5819)
@@ -27,5 +27,5 @@
 // The goal of the seperate error file is to make the first
 // step towards localization. tinyxml (currently) only supports
-// latin-1, but at least the error messages could now be translated.
+// english error messages, but the could now be translated.
 //
 // It also cleans up the code a bit.
@@ -49,3 +49,4 @@
 	"Error document empty.",
 	"Error null (0) or unexpected EOF found in input stream.",
+	"Error parsing CDATA.",
 };
Index: trunk/src/lib/tinyxml/tinyxmlparser.cc
===================================================================
--- trunk/src/lib/tinyxml/tinyxmlparser.cc	(revision 5793)
+++ trunk/src/lib/tinyxml/tinyxmlparser.cc	(revision 5819)
@@ -718,4 +718,5 @@
 		{
 			encoding = TIXML_ENCODING_UTF8;
+			useMicrosoftBOM = true;
 		}
 	}
@@ -786,5 +787,4 @@
 	if ( pError && data )
 	{
-		//TiXmlParsingData data( pError, prevData );
 		data->Stamp( pError, encoding );
 		errorLocation = data->Cursor();
@@ -821,4 +821,5 @@
 	const char* commentHeader = { "<!--" };
 	const char* dtdHeader = { "<!" };
+	const char* cdataHeader = { "<![CDATA[" };
 
 	if ( StringEqual( p, xmlHeader, true, encoding ) )
@@ -835,4 +836,13 @@
 		#endif
 		returnNode = new TiXmlComment();
+	}
+	else if ( StringEqual( p, cdataHeader, false, encoding ) )
+	{
+		#ifdef DEBUG_PARSER
+			TIXML_LOG( "XML parsing CDATA\n" );
+		#endif
+		TiXmlText* text = new TiXmlText( "" );
+		text->SetCDATA( true );
+		returnNode = text;
 	}
 	else if ( StringEqual( p, dtdHeader, false, encoding ) )
@@ -931,5 +941,5 @@
 			if ( !in->good() ) return;
 			assert( in->peek() == '<' );
-			int tagIndex = tag->length();
+			int tagIndex = (int) tag->length();
 
 			bool closingTag = false;
@@ -1013,5 +1023,4 @@
 	}
 
-//	TiXmlParsingData data( p, prevData );
 	if ( data )
 	{
@@ -1127,7 +1136,8 @@
 	TiXmlDocument* document = GetDocument();
 
+	// Read in text and elements in any order.
 	const char* pWithWhiteSpace = p;
-	// Read in text and elements in any order.
 	p = SkipWhiteSpace( p, encoding );
+
 	while ( p && *p )
 	{
@@ -1162,5 +1172,6 @@
 		{
 			// We hit a '<'
-			// Have we hit a new element or an end tag?
+			// Have we hit a new element or an end tag? This could also be
+			// a TiXmlText in the "CDATA" style.
 			if ( StringEqual( p, "</", false, encoding ) )
 			{
@@ -1181,4 +1192,5 @@
 			}
 		}
+		pWithWhiteSpace = p;
 		p = SkipWhiteSpace( p, encoding );
 	}
@@ -1222,5 +1234,4 @@
 	p = SkipWhiteSpace( p, encoding );
 
-//	TiXmlParsingData data( p, prevData );
 	if ( data )
 	{
@@ -1286,5 +1297,4 @@
 	p = SkipWhiteSpace( p, encoding );
 
-//	TiXmlParsingData data( p, prevData );
 	if ( data )
 	{
@@ -1315,5 +1325,4 @@
 		tabsize = document->TabSize();
 
-//	TiXmlParsingData data( p, prevData );
 	if ( data )
 	{
@@ -1378,9 +1387,7 @@
 void TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
 {
-	while ( in->good() )
-	{
-		int c = in->peek();	
-		if ( c == '<' )
-			return;
+	if ( cdata )
+	{
+		int c = in->get();	
 		if ( c <= 0 )
 		{
@@ -1392,5 +1399,31 @@
 
 		(*tag) += (char) c;
-		in->get();
+
+		if ( c == '>' 
+			 && tag->at( tag->length() - 2 ) == ']'
+			 && tag->at( tag->length() - 3 ) == ']' )
+		{
+			// All is well.
+			return;		
+		}
+	}
+	else
+	{
+		while ( in->good() )
+		{
+			int c = in->peek();	
+			if ( c == '<' )
+				return;
+			if ( c <= 0 )
+			{
+				TiXmlDocument* document = GetDocument();
+				if ( document )
+					document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
+				return;
+			}
+
+			(*tag) += (char) c;
+			in->get();
+		}
 	}
 }
@@ -1400,5 +1433,6 @@
 {
 	value = "";
-//	TiXmlParsingData data( p, prevData );
+	TiXmlDocument* document = GetDocument();
+
 	if ( data )
 	{
@@ -1406,11 +1440,42 @@
 		location = data->Cursor();
 	}
-	bool ignoreWhite = true;
-
-	const char* end = "<";
-	p = ReadText( p, &value, ignoreWhite, end, false, encoding );
-	if ( p )
-		return p-1;	// don't truncate the '<'
-	return 0;
+
+	const char* const startTag = "<![CDATA[";
+	const char* const endTag   = "]]>";
+
+	if ( cdata || StringEqual( p, startTag, false, encoding ) )
+	{
+		cdata = true;
+
+		if ( !StringEqual( p, startTag, false, encoding ) )
+		{
+			document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
+			return 0;
+		}
+		p += strlen( startTag );
+
+		// Keep all the white space, ignore the encoding, etc.
+		while (	   p && *p
+				&& !StringEqual( p, endTag, false, encoding )
+			  )
+		{
+			value += *p;
+			++p;
+		}
+
+		TIXML_STRING dummy; 
+		p = ReadText( p, &dummy, false, endTag, false, encoding );
+		return p;
+	}
+	else
+	{
+		bool ignoreWhite = true;
+
+		const char* end = "<";
+		p = ReadText( p, &value, ignoreWhite, end, false, encoding );
+		if ( p )
+			return p-1;	// don't truncate the '<'
+		return 0;
+	}
 }
 
@@ -1450,5 +1515,4 @@
 		return 0;
 	}
-//	TiXmlParsingData data( p, prevData );
 	if ( data )
 	{
