• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/xml/XmlElement.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _xmlelement_h
00018 #define _xmlelement_h
00019 
00020 #include <spl/Debug.h>
00021 #include <spl/Double.h>
00022 #include <spl/Int32.h>
00023 #include <spl/xml/XmlAttributeCollection.h>
00024 #include <spl/xml/XmlNode.h>
00025 
00034 class XmlElement : public XmlNode
00035 {
00036 protected:
00037         friend class XmlNode;
00038         friend class XmlText;
00039         friend class XmlAttribute;
00040         friend void _TestTinyXml();
00041 
00042         String m_name;
00043         XmlAttributeCollectionPtr m_attribs;
00044         
00045         const char* ReadValue( const char* in, XmlParsingData* prevData, XmlEncoding encoding );
00046         void ClearThis();       // like clear, but initializes 'this' object as well
00047         void CopyTo( XmlElement& target ) const;
00048 
00049         /*      Attribtue parsing starts: next char past '<'
00050                                                  returns: next char past '>'
00051         */
00052         virtual const char* _Parse( const char* p, XmlParsingData* data, XmlEncoding encoding );
00053 
00055         XmlElement (const String& in_value);
00056 
00057 public:
00058         XmlElement( const XmlElement& );
00059         virtual ~XmlElement();
00060 
00061         virtual String Name() const;
00062                         
00063         void operator =( const XmlElement& base );
00064         
00065         XmlElementPtr ChildElement( const String& value, int index );
00066         XmlElementPtr ChildElement( int index );
00067 
00071         //const XmlAttribute* Attribute( const String *name ) const;
00072         inline XmlAttributePtr Attribute( const String& name ) const
00073         {
00074                 if ( m_attribs.IsNull() )
00075                 {
00076                         return XmlAttributePtr();
00077                 }
00078                 return m_attribs->Find( name );
00079         }
00080 
00081         inline XmlAttributePtr Attribute( int index ) const
00082         {
00083                 if ( m_attribs.IsNull() )
00084                 {
00085                         return XmlAttributePtr();
00086                 }
00087                 return (XmlAttributePtr)m_attribs->Item(index);
00088         }
00089 
00093         void SetAttribute( const String& name, const String& _value );
00094 
00098         inline void SetAttribute( const String& name, int val )
00099         {       
00100                 SetAttribute( name, *Int32::ToString(val) );
00101         }
00102         
00106         inline void SetAttribute( const String& name, double value )
00107         {
00108                 SetAttribute( name, *Double::ToString(value) );
00109         }
00110 
00113         void RemoveAttribute( const String& name );
00114 
00115         inline XmlAttributeCollectionPtr Attributes() { return m_attribs; } 
00116 
00149         /*String GetText() const;*/
00150         virtual StringPtr InnerText() const;
00151 
00153         virtual XmlNodePtr Clone() const;
00154 
00155         virtual XmlElementPtr     ToElement()     const; 
00156         
00157         virtual StringPtr InnerXml() const;
00158         virtual StringPtr ToString() const;
00159         virtual void WriteTo(TextWriter& writer) const;
00160 
00161         static XmlElementPtr CreateElement(const String& name);
00162                         
00163 #ifdef DEBUG
00164         virtual void ValidateMem() const;
00165         virtual void CheckMem() const;
00166 #endif
00167 };
00168 
00169 REGISTER_TYPEOF( 538, XmlElement );
00170 
00173 #endif