BContent.h

Go to the documentation of this file.
00001 #ifndef _B_XML_CONTENT_H
00002 #define _B_XML_CONTENT_H
00003 
00004 #include <xml/BXMLDefs.h>
00005 #include <xml/BStringMap.h>
00006 
00007 #include <String.h>
00008 
00009 namespace B {
00010 namespace XML {
00011 
00012 
00013 // Forward References
00014 // =====================================================================
00015 class BXMLObject;
00016 class BNamespace;
00017 class BContent;
00018 class BNamed;
00019 class BElement;
00020 class BDocument;
00021 class BValued;
00022 class BAttribute;
00023 class BText;
00024 class BCData;
00025 class BComment;
00026 class BNamedSet;
00027 class BDocumentType;
00028 class BProcessingInstruction;
00029 class BDocumentTypeDefinition;
00030 class BDocumentTypeDefinition;
00031 class BElementDecl;
00032 class BAttributeDecl;
00033 class BEntityDecl;
00034 class BXMLObjectFactory;
00035 class BEntityStore;
00036 
00037 
00038 // Some Sets of Pointers
00039 // =====================================================================
00040 // XXX should be fixed to be standard names
00041 typedef _Pointer_Set_<BElement *>       ElementSet;
00042 typedef _Pointer_Set_<BXMLObject *>     XMLObjectSet;           
00043 typedef _Pointer_Set_<BXMLObject *>     BXMLObjectSet;
00044 typedef _Pointer_Set_<BString *>        _StringSet_;
00045 
00046 
00047 // Generic Type Coded XML Object
00048 // =====================================================================
00049 // Some xml objects (specifically BAttribute) don't have much in common
00050 // functionally, but they all need a common base class.
00051 class BXMLObject
00052 {
00053 public:
00054                             BXMLObject(uint32 type);
00055     virtual                 ~BXMLObject();
00056     
00057                             // Type Code
00058     uint32                  Type() const;
00059     
00060 private:
00061     uint32                  _type;
00062 };
00063 
00064 
00065 // XML Content
00066 // =====================================================================
00067 // Base class of the classes that make up the document structure.
00068 class BContent : public BXMLObject
00069 {
00070 public:
00071                             // All elements have parents except for the
00072                             // root element, where this returns null
00073     BElement                * Parent();
00074     const BElement          * Parent() const;
00075     
00076                             // Each node has a pointer to the document it's
00077                             // in (if it's in a document).  
00078     BDocument               * Document();
00079     const BDocument         * Document() const;
00080     
00081                             // The next sibling in document order.
00082                             // Mask looks until the next one that matches mask
00083                             // Element is a convience wrapper for NextSibMask(ELEMENT);
00084     BContent                * NextSibling();
00085     const BContent          * NextSibling() const;
00086     BContent                * NextSibling(uint32 typeMask);
00087     const BContent          * NextSibling(uint32 typeMask) const;
00088     BContent                * PreviousSibling();
00089     const BContent          * PreviousSibling() const;
00090     BContent                * PreviousSibling(uint32 typeMask);
00091     const BContent          * PreviousSibling(uint32 typeMask) const;
00092     
00093     BElement                * NextSiblingElement();
00094     const BElement          * NextSiblingElement() const;
00095     BElement                * PreviousSiblingElement();
00096     const BElement          * PreviousSiblingElement() const;
00097     
00098     virtual BContent        * Clone() const;
00099     
00100 protected:
00101     
00102                             // You get a copy that is not connected to the document
00103                             // hierarchy
00104     explicit                BContent(const BContent & copy);
00105     
00106                             // Never create a plain BContent
00107                             BContent(uint32 type);
00108     
00109     virtual                 ~BContent();
00110     
00111 private:
00112                             // Always need a type
00113                             BContent();
00114     
00115     bool                    check_content_for_connections();
00116     status_t                set_parent(BElement * parent);
00117     status_t                set_next_sibling(BContent * sibling);
00118     status_t                set_prev_sibling(BContent * sibling);
00119     status_t                set_document(BDocument * document);
00120     
00121     BElement                * _parent;
00122     BContent                * _nextSibling;
00123     BContent                * _prevSibling;
00124     BDocument               * _document;
00125     
00126     friend class BElement;      // BElement manages its list of elements
00127     friend class BDocument;     // BDocument manages its list of elements
00128 };
00129 
00130 
00131 // XML Named
00132 // =====================================================================
00133 // Simple mechanism for giving elements and attributes a name
00134 // There is a corresponding BNamedSet that allows access to
00135 // named things.
00136 class BNamed
00137 {
00138 public:
00139     const char          * Name() const;
00140     
00141     virtual             ~BNamed();
00142 
00143 protected:
00144     explicit            BNamed(const BNamed & copy);
00145     
00146                         BNamed(const char * name);
00147                         BNamed(const BString & name);
00148                         BNamed(BString & name, bool adopt = false);
00149     
00150                         // protected, because not all named things have namespaces
00151     BNamespace          * Namespace();
00152     const BNamespace    * Namespace() const;
00153     
00154     virtual void        SetName(const char * name);
00155     virtual status_t    SetNamespace(BNamespace * space);
00156     
00157 private:
00158     BString             _name;
00159     BNamespace          * _namespace;
00160     
00161     friend class BNamedSet; // BNamedSet uses the protected Namespace() function
00162 };
00163 
00164 
00165 // XML Namespace
00166 // =====================================================================
00167 // This gets attached to an element or document, and pointed to by
00168 // BNamed objects that are in that namespace
00169 // The BNamed base class is the name of the prefix, because that's
00170 // what we look up by
00171 class BNamespace : public BNamed
00172 {
00173 public:
00174                     BNamespace(const BNamespace & copy);
00175                     BNamespace(const char * prefix, const char * value);
00176                     BNamespace(const BString & prefix, const BString & value);
00177                     BNamespace(BString & prefix, BString & value, bool adopt);
00178     
00179     virtual         ~BNamespace();
00180     
00181     const char *    Value() const;
00182     
00183                                     // Claims ownership
00184     virtual void                    SetDTD(BDocumentTypeDefinition * dtd);
00185     
00186     const BDocumentTypeDefinition   * GetDTD() const;
00187     BDocumentTypeDefinition         * GetDTD();
00188     
00189 private:
00190                                 BNamespace();
00191     
00192     BString                     _value;
00193     BDocumentTypeDefinition     * _dtd;
00194     
00195     friend class BNamedSet;
00196 };
00197 
00198 
00199 // Set of things with names
00200 // =====================================================================
00201 // Provides a set of BXMLNamed objects.  Used to keep track of attributes
00202 // and some of the DTD declarations.  If you go through in index order,
00203 // you get list sorted by name.
00204 class BNamedSet
00205 {
00206 public:
00207                             BNamedSet();
00208     virtual                 ~BNamedSet();
00209     
00210     virtual status_t        Add(BNamed * named);
00211     virtual void            Remove(BNamed * named);
00212     virtual void            Remove(int32 index);
00213     virtual BNamed          * Find(const char * name);
00214     virtual const BNamed    * Find(const char * name) const;
00215     
00216     int32                   CountItems() const;
00217     BNamed                  * ItemAt(int32 index);
00218     const BNamed            * ItemAt(int32 index) const;
00219     
00220     virtual void            MakeEmpty(bool deleteData);
00221     
00222 private:
00223     _Pointer_Set_<BNamed *> _data;
00224 }; 
00225 
00226 
00227 // XML Element
00228 // =====================================================================
00229 // BElement maps directly to the element construction in an XML document.
00230 // Only BElement know about their children, and the only way to add an
00231 // element to ta document is to add it to an element, even though it is
00232 // actually stored as a linked list.
00233 // All the add functions take ownership -- don't try to delete things you add
00234 class BElement : public BContent, public BNamed
00235 {
00236 public:
00237     
00238     // --- Constructor and Destructor  ----------------------
00239                             BElement(const char * name);
00240                             BElement(const BString & name);
00241                             BElement(BString & name, bool adopt = false);
00242                             BElement(const BElement & copy);
00243     virtual                 ~BElement();
00244     
00245     virtual BContent        * Clone() const;
00246     BElement                & operator=(const BElement & copy);
00247     
00248     // --- Namespaces ---------------------------------------
00249                             // Add this element to the namespace space
00250     virtual status_t        SetNamespace(BNamespace * space);
00251     using                   BNamed::Namespace;
00252     
00253     virtual status_t        AddNamespace(BNamespace * space);
00254     
00255     int32                   CountNamespaces() const;
00256     BNamespace              * NamespaceAt(int32 index);
00257     const BNamespace        * NamespaceAt(int32 index) const;
00258     
00259     BNamespace              * FindNamespaceByPrefix(const char * prefix);
00260     const BNamespace        * FindNamespaceByPrefix(const char * prefix) const;
00261     BNamespace              * FindNamespaceByValue(const char * value);
00262     const BNamespace        * FindNamespaceByValue(const char * value) const;
00263     
00264                             // Find the element that the namespace is declared in.
00265                             // NULL if we can't find it.  The element will be either
00266                             // this element or one of its parents
00267     BElement                * FindNamespaceDecl(const BNamespace * space);
00268     const BElement          * FindNamespaceDecl(const BNamespace * space) const;
00269     
00270     // --- Getting Children ---------------------------------
00271                             // Access to the first and last children for iteration
00272                             // iteration over all of the children of any type.
00273                             // With a mask, it will find the first that fits it
00274     BContent                * FirstChild();
00275     const BContent          * FirstChild() const;
00276     BContent                * FirstChild(uint32 typeMask);
00277     const BContent          * FirstChild(uint32 typeMask) const;
00278     BContent                * LastChild();
00279     const BContent          * LastChild() const;
00280     BContent                * LastChild(uint32 typeMask);
00281     const BContent          * LastChild(uint32 typeMask) const;
00282     
00283                             // Find the index of the first element named
00284                             // <name> at or after index <atOrAfter>
00285     status_t                FindElementNamed(const char * name, BElement ** element);
00286     
00287     // --- Adding Children ----------------------------------
00288                             // Make it the first one, take ownership
00289     virtual status_t        AddChildFirst(BContent * content);
00290     
00291                             // Make it the last one, take ownership
00292     virtual status_t        AddChildLast(BContent * content);
00293     
00294                             // Put it before <before>, take ownership
00295     virtual status_t        AddChildBefore(BContent * content, BContent * before);
00296     
00297                             // Put it after <after>, take ownership
00298     virtual status_t        AddChildAfter(BContent * content, BContent * after);
00299     
00300     // --- Removing Children --------------------------------
00301                             // Does not delete it
00302     virtual status_t        RemoveChild(BContent * content);
00303     
00304     // --- Add Attributes -----------------------------------
00305     // The only way to find attributes is through their element.  Because they are
00306     // attached through a BXMLNamedSet, not through the BXMLNode linked list mechanism.
00307     
00308     // replace says what to do if it's already there:
00309     //     false: return an error if it already exists
00310     //     true:  replace it and return B_OK
00311     
00312                             // The other add attributes call this one
00313     virtual status_t        AddAttribute(BAttribute * attribute, bool replace = false);
00314     
00315     virtual status_t        AddAttribute(const char * name, const char * val, bool replace = false);
00316     virtual status_t        AddAttribute(const char * name, const BString & val, bool replace = false);
00317 
00318 #if !_SMALL_XML_FOOTPRINT_
00319     virtual status_t        AddAttribute(const char * name, BRect val, bool replace = false);
00320     virtual status_t        AddAttribute(const char * name, BPoint val, bool replace = false);
00321     virtual status_t        AddAttribute(const char * name, int8 val, bool replace = false);
00322     virtual status_t        AddAttribute(const char * name, int16 val, bool replace = false);
00323     virtual status_t        AddAttribute(const char * name, int32 val, bool replace = false);
00324     virtual status_t        AddAttribute(const char * name, int64 val, bool replace = false);
00325     virtual status_t        AddAttribute(const char * name, uint8 val, bool replace = false);
00326     virtual status_t        AddAttribute(const char * name, uint16 val, bool replace = false);
00327     virtual status_t        AddAttribute(const char * name, uint32 val, bool replace = false);
00328     virtual status_t        AddAttribute(const char * name, uint64 val, bool replace = false);
00329     virtual status_t        AddAttribute(const char * name, bool val, bool replace = false);
00330     virtual status_t        AddAttribute(const char * name, float val, bool replace = false);
00331     virtual status_t        AddAttribute(const char * name, double val, bool replace = false);
00332                             // Will always use #xxxxxx format
00333     virtual status_t        AddAttributeRGBColor(const char * name, rgb_color val, bool replace = false);
00334                             // Will use HTML 4 colors if possible, else will use #xxxxxx format
00335     virtual status_t        AddAttributeHTMLColor(const char * name, rgb_color val, bool replace = false);
00336                             // If it's in the same document, will give an XPath to it
00337     virtual status_t        AddAttributeXPath(const char * name, BContent * which, bool replace = false);
00338 #endif
00339     
00340     
00341     // --- Find Attributes ----------------------------------
00342     int32                   CountAttributes() const;
00343     BAttribute              * AttributeAt(int32 index) const;
00344     
00345                             // Is there an attribute that exactly matches attribute, but may or
00346                             // may not actually be the same object.
00347     bool                    FindAttribute(const BAttribute * attribute) const;
00348     
00349     // Find by name
00350     status_t                FindAttribute(const char * name, BAttribute ** attribute);
00351     status_t                FindAttribute(const char * name, const BAttribute ** attribute) const;
00352     status_t                FindAttribute(const char * name, const char ** val) const;
00353     status_t                FindAttribute(const char * name, BString * val) const;
00354     
00355 #if !_SMALL_XML_FOOTPRINT_
00356     status_t                FindAttribute(const char * name, BRect * val) const;
00357     status_t                FindAttribute(const char * name, BPoint * val) const;
00358     status_t                FindAttribute(const char * name, int8 * val) const;
00359     status_t                FindAttribute(const char * name, int16 * val) const;
00360     status_t                FindAttribute(const char * name, int32 * val) const;
00361     status_t                FindAttribute(const char * name, int64 * val) const;
00362     status_t                FindAttribute(const char * name, uint8 * val) const;
00363     status_t                FindAttribute(const char * name, uint16 * val) const;
00364     status_t                FindAttribute(const char * name, uint32 * val) const;
00365     status_t                FindAttribute(const char * name, uint64 * val) const;
00366     status_t                FindAttribute(const char * name, bool * val) const;
00367     status_t                FindAttribute(const char * name, float * val) const;
00368     status_t                FindAttribute(const char * name, double * val) const;
00369     status_t                FindAttribute(const char * name, rgb_color * val) const;
00370                             // Will try to find a pointer to a BXMLNode at that XPath
00371     status_t                FindAttributeXPath(const char * name, BContent ** which);
00372 #endif
00373     
00374     // These take a default argument, if it doesn't find the attribute, it gives
00375     // you the default and returns false.  If it does find it it gives it to you
00376     // and returns true.  Use these if you don't want to do error checking, and you
00377     // have a default value that you can use without a problem.
00378     //
00379     // Replaces the code:
00380     // int32 val;
00381     // if (element->FindAttribute("name", &val) != B_OK)
00382     //      val = 5;
00383     //
00384     // With:
00385     // element->FindAttribute("name", &val, 5);
00386     //
00387 
00388     bool                    FindAttribute(const char * name, const char ** val, const char * def) const;
00389     bool                    FindAttribute(const char * name, BString * val, const char * def) const;
00390 
00391 #if !_SMALL_XML_FOOTPRINT_
00392     bool                    FindAttribute(const char * name, BRect * val, BRect def) const;
00393     bool                    FindAttribute(const char * name, BPoint * val, BPoint def) const;
00394     bool                    FindAttribute(const char * name, int8 * val, int8 def) const;
00395     bool                    FindAttribute(const char * name, int16 * val, int16 def) const;
00396     bool                    FindAttribute(const char * name, int32 * val, int32 def) const;
00397     bool                    FindAttribute(const char * name, int64 * val, int64 def) const;
00398     bool                    FindAttribute(const char * name, uint8 * val, uint8 def) const;
00399     bool                    FindAttribute(const char * name, uint16 * val, uint16 def) const;
00400     bool                    FindAttribute(const char * name, uint32 * val, uint32 def) const;
00401     bool                    FindAttribute(const char * name, uint64 * val, uint64 def) const;
00402     bool                    FindAttribute(const char * name, bool * val, bool def) const;
00403     bool                    FindAttribute(const char * name, float * val, float def) const;
00404     bool                    FindAttribute(const char * name, double * val, double def) const;
00405     bool                    FindAttribute(const char * name, rgb_color * val, rgb_color def) const;
00406                             // Will try to find a pointer to a BXMLNode at that XPath
00407                             // The default in this function isn't all that useful
00408     bool                    FindAttributeXPath(const char * name, BContent ** which, BContent * def);
00409 #endif  
00410     
00411     // --- Remove Attributes --------------------------------
00412                             // Does not delete <attribute>
00413     virtual status_t        RemoveAttribute(BAttribute * attribute);
00414                             // Deletes the internally stored BAttribute
00415     virtual status_t        RemoveAttribute(const char * name);
00416     
00417     // --- Some Interesting Functions -----------------------
00418                             // Put this element into some normalized form.  TBD.
00419                             // For example, coalesce adjacent text or CData nodes
00420     // virtual void         Normalize();
00421     
00422     
00423     // --- Value of the Element... --------------------------
00424     
00425     // If the data inside this element can be coalesced by removing comments and/or
00426     // processing instructions, and joining all text and CData, then these functions
00427     // can get the values of the result of that coalescing.  If not, return an error.
00428     // Could also possibly put some convience methods into here to make
00429     // it do some fun stuff with attributes elements.  
00430     // For example, to get a rect, look at the top, left, bottom, right attributes,
00431     // if they all exist and can be floating point numbers, then this function would
00432     // work.  More thought needed here
00433     //
00434     // This makes the following constructs simple to access, where they would be a
00435     // pain; but it's a fairly common piece of XML.
00436     //      <Element>42</Element>   gives: "42"
00437     //      <Element>Whoah <!-- Hey Dude -->Momma!</Element>    gives: "Whoah Momma!"
00438     //      <Element>Whoah<!-- Hey Dude -->Momma!</Element>    gives: "WhoahMomma!"
00439     
00440     status_t                GetData(BString * data) const;
00441     
00442 #if 0 && !_SMALL_XML_FOOTPRINT_
00443     status_t                GetData(BRect * data);
00444     status_t                GetData(BPoint * data);
00445     status_t                GetData(int8 * data);
00446     status_t                GetData(int16 * data);
00447     status_t                GetData(int32 * data);
00448     status_t                GetData(int64 * data);
00449     status_t                GetData(uint8 * data);
00450     status_t                GetData(uint16 * data);
00451     status_t                GetData(uint32 * data);
00452     status_t                GetData(uint64 * data);
00453     status_t                GetData(bool * data);
00454     status_t                GetData(float * data);
00455     status_t                GetData(double * data);
00456     status_t                GetData(rgb_color * data);
00457     status_t                GetDataXPath(BContent * pathTo);
00458     
00459     // Similar idea as before, except here we set it.  This just fails if there
00460     // are already any children except a single text or a CData present.  Create
00461     // a Text object if there is nothing.  XXX Requires a factory method... ugh.
00462     virtual status_t        SetData(const char * data);
00463     virtual status_t        SetData(BString * data);
00464     virtual status_t        SetData(BRect * data);
00465     virtual status_t        SetData(BPoint * data);
00466     virtual status_t        SetData(int8 * data);
00467     virtual status_t        SetData(int16 * data);
00468     virtual status_t        SetData(int32 * data);
00469     virtual status_t        SetData(int64 * data);
00470     virtual status_t        SetData(uint8 * data);
00471     virtual status_t        SetData(uint16 * data);
00472     virtual status_t        SetData(uint32 * data);
00473     virtual status_t        SetData(uint64 * data);
00474     virtual status_t        SetData(bool * data);
00475     virtual status_t        SetData(float * data);
00476     virtual status_t        SetData(double * data);
00477     virtual status_t        SetData(rgb_color * data);
00478     
00479     virtual status_t        SetDataXPath(BContent * pathTo);
00480 #endif
00481 
00482 
00483 private:
00484     
00485     BContent            * _firstChild;
00486     BContent            * _lastChild;
00487     BNamedSet           _attributes;
00488     BNamedSet           _namespaces;
00489 };
00490 
00491 
00492 // XML Valued
00493 // =====================================================================
00494 // BValued does not attempt to coalesce anything like BElement does --
00495 // they don't have children.
00496 class BValued
00497 {
00498 public:
00499     
00500     // --- Getting Value ------------------------------------
00501     status_t                GetValue(const char ** value) const;
00502     status_t                GetValue(BString * value) const;
00503 
00504 #if !_SMALL_XML_FOOTPRINT_
00505     status_t                GetValue(BRect * value) const;
00506     status_t                GetValue(BPoint * value) const;
00507     status_t                GetValue(int8 * value) const;
00508     status_t                GetValue(int16 * value) const;
00509     status_t                GetValue(int32 * value) const;
00510     status_t                GetValue(int64 * value) const;
00511     status_t                GetValue(uint8 * value) const;
00512     status_t                GetValue(uint16 * value) const;
00513     status_t                GetValue(uint32 * value) const;
00514     status_t                GetValue(uint64 * value) const;
00515     status_t                GetValue(bool * value) const;
00516     status_t                GetValue(float * value) const;
00517     status_t                GetValue(double * value) const;
00518     status_t                GetValue(rgb_color * value) const;
00519     virtual status_t        GetValueXPath(BContent ** pathTo);
00520 #endif
00521     
00522                             // This function gets what you would see if you
00523                             // outputed to XML and read with StyledEdit.
00524     virtual void            GetValueRaw(BString & value) const;
00525     
00526     // --- Setting Value ------------------------------------
00527     virtual status_t        SetValue(const char * value);
00528     virtual status_t        SetValue(const char * value, int32 length);
00529     
00530                             // Adopt takes the buffer from value, so there
00531                             // is no copy.
00532     virtual status_t        SetValue(BString & value, bool adopt = false);
00533     
00534 #if !_SMALL_XML_FOOTPRINT_
00535     virtual status_t        SetValue(BRect value);
00536     virtual status_t        SetValue(BPoint value);
00537     virtual status_t        SetValue(int8 value);
00538     virtual status_t        SetValue(int16 value);
00539     virtual status_t        SetValue(int32 value);
00540     virtual status_t        SetValue(int64 value);
00541     virtual status_t        SetValue(uint8 value);
00542     virtual status_t        SetValue(uint16 value);
00543     virtual status_t        SetValue(uint32 value);
00544     virtual status_t        SetValue(uint64 value);
00545     virtual status_t        SetValue(bool value);
00546     virtual status_t        SetValue(float value);
00547     virtual status_t        SetValue(double value);
00548     virtual status_t        SetValueRGBColor(rgb_color value);
00549     virtual status_t        SetValueHTMLColor(rgb_color value);
00550     virtual status_t        SetValueXPath(BContent * pathTo);
00551 #endif
00552 
00553     // --- Useful Functions ---------------------------------
00554                             // Start will become the index of the first char (-1 for end)
00555                             // Len is the number of chars to replace/delete, etc. (-1 is all)
00556     virtual status_t        Append(const char * str);
00557     virtual status_t        Insert(const char * str, int32 start = -1);
00558     virtual status_t        Remove(int32 start = -1, int32 len = -1);
00559     virtual status_t        Replace(const char * str, int32 start = 0, int32 len = -1);
00560     
00561 protected:
00562     // --- Validation ---------------------------------------
00563                             // Hook function.  Easier than re-implementing
00564                             // all of the virtual set functions
00565                             // Check to see if the new value is okay
00566                             // return fals if it's not
00567                             // default impl returns true to approve it
00568                             // e.g. used by attribute to validate types
00569     virtual status_t        ValidateValueChange(BString & newVal);
00570     
00571 public:
00572     explicit                BValued(const BValued & copy);
00573                             BValued(const char * value);
00574                             BValued(const BString & copy);
00575                             BValued();
00576     virtual                 ~BValued();
00577     
00578 protected:
00579     // Give access just for efficiency.
00580     // Do not change this value directly, because ValidateValueChange will not be called.
00581     BString                 _value;
00582 };
00583 
00584 
00585 // XML Attribute
00586 // =====================================================================
00587 // Elements are stored as a set of attributes and an ordered set of children
00588 // nodes.  This is the object that represents attributes.
00589 // All the value methods come from the BXMLValued class
00590 class BAttribute    : public BValued, public BNamed, public BXMLObject
00591 {
00592 public:
00593                             BAttribute(const char * name);
00594                             BAttribute(const char * name, const char * value);
00595                             BAttribute(const BString & name);
00596                             BAttribute(BString & name, bool adopt = false);
00597                             BAttribute(const BAttribute & copy); // deep copy
00598     virtual                 ~BAttribute();
00599     virtual BAttribute      * Clone() const;
00600     
00601                             // Properly esacpes meaningful xml characters
00602     virtual void            GetValueRaw(BString & value) const;
00603     
00604     virtual status_t        SetNamespace(BNamespace * space);
00605     using                   BNamed::Namespace;
00606     
00607 private:
00608                             BAttribute();
00609 };
00610 
00611 
00612 // XML Processing Instruction
00613 // =====================================================================
00614 class BProcessingInstruction    : public BValued, public BNamed, public BContent
00615 {
00616 public:
00617                             BProcessingInstruction(const char * target);
00618                             BProcessingInstruction(const char * name, const char * value);
00619                             BProcessingInstruction(const BString & name);
00620                             BProcessingInstruction(BString & name, bool adopt = false);
00621                             BProcessingInstruction(const BProcessingInstruction & copy);    // deep copy
00622     
00623     virtual                 ~BProcessingInstruction();
00624     
00625     virtual BProcessingInstruction  * Clone() const;
00626     
00627     virtual void            GetValueRaw(BString & value) const;
00628 private:
00629                             BProcessingInstruction();
00630 };
00631 
00632 
00633 // XML Text
00634 // =====================================================================
00635 // Text is character data that might get escaped when written to XML.
00636 class BText : public BContent, public BValued
00637 {
00638 public:
00639                             BText();
00640                             BText(const BText & copy);
00641                             BText(const char * value);
00642                             BText(const BString & value);
00643     virtual                 ~BText();
00644     virtual BContent        * Clone() const;
00645 };
00646 
00647 
00648 // XML CData
00649 // =====================================================================
00650 // CData is text that does not get escaped, except for one case. It
00651 // gets surrounded by the strings "<![CDATA[" and "]]>".  So if the
00652 // string "]]>" appears in the string will be escaped to "]]&gt;"
00653 // as required by Section 2.4 of the XML spec.
00654 // The only difference between BText and BCData is how it is displayed
00655 // in XML
00656 class BCData : public BContent, public BValued
00657 {
00658 public:
00659                             BCData();
00660                             BCData(const BCData & copy);
00661                             BCData(const char * value);
00662                             BCData(const BString & value);
00663     virtual                 ~BCData();
00664     virtual BContent        * Clone() const;
00665 };
00666 
00667 
00668 // XML Comment
00669 // =====================================================================
00670 class BComment : public BContent, public BValued
00671 {
00672 public:
00673                             BComment();
00674                             BComment(const BComment & copy);
00675                             BComment(const char * value);
00676                             BComment(const BString & value);
00677     virtual                 ~BComment();
00678     virtual BContent        * Clone() const;
00679     
00680                             // Comments are escaped slightly differently
00681     virtual void            GetValueRaw(BString & value) const;
00682     
00683 private:
00684                             // some substrings are illegal in comments
00685     virtual status_t        ValidateValueChange(BString & newVal);
00686 };
00687 
00688 
00689 // XML Document
00690 // =====================================================================
00691 // This class represents the document as a whole. It looks like an
00692 // element, but it's not.  The document element has its parent set to NULL
00693 // If it's NULL, you can always access the document through the Document() function.
00694 // It's also not derived from BContent
00695 // The document does not derive from element, but it has a bunch of similar
00696 // functions, but it is much more limiting, because what a document can
00697 // contain directly is limited by the XML spec.
00698 class BDocument : public BXMLObject
00699 {
00700 public:
00701     
00702     // --- Constructor and Destructor  ----------------------
00703                             BDocument();
00704                             BDocument(const BDocument & copy);
00705     virtual                 ~BDocument();
00706     
00707     
00708     // --- Getting Children ---------------------------------
00709                             // Access to the first and last children for iteration
00710                             // iteration over all of the children of any type.
00711                             // With a mask, it will find the first that fits it
00712     BContent                * FirstChild();
00713     const BContent          * FirstChild() const;
00714     BContent                * FirstChild(uint32 typeMask);
00715     const BContent          * FirstChild(uint32 typeMask) const;
00716     BContent                * LastChild();
00717     const BContent          * LastChild() const;
00718     BContent                * LastChild(uint32 typeMask);
00719     const BContent          * LastChild(uint32 typeMask) const;
00720 
00721                             // Access to some of the interesting children
00722     BDocumentType           * DocumentType();
00723     const BDocumentType     * DocumentType() const;
00724     BElement                * Element();
00725     const BElement          * Element() const;
00726     
00727     
00728     // --- Adding Children ----------------------------------
00729                             // Make it the first one, take ownership of <content>
00730     virtual status_t        AddChildFirst(BContent * content);
00731                             // Make it the last one, take ownership of <content>
00732     virtual status_t        AddChildLast(BContent * content);
00733                             // Put it before <before>, take ownership of <content>
00734     virtual status_t        AddChildBefore(BContent * content, BContent * before);
00735                             // Put it after <after>, take ownership of <content>
00736     virtual status_t        AddChildAfter(BContent * content, BContent * after);
00737     
00738     // --- Removing Children --------------------------------
00739                             // Will not delete <content>
00740     virtual status_t        RemoveChild(BContent * content);
00741     
00742 
00743     // --- Some Interesting Functions -----------------------
00744                             // If there is a DTD, set it back to the default provided by
00745                             // the DTD.  If there isn't a DTD, empty it out.  Also deletes
00746                             // objects.  No leakage.
00747     // virtual status_t     ResetAll();
00748     // virtual status_t     ResetAttributes();
00749     // virtual status_t