Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members

doc.h

Go to the documentation of this file.
00001 #ifndef DVXML_DOC_H
00002 #define DVXML_DOC_H
00003 
00004 #include <stdexcept>
00005 #include <iterator>
00006 #include <dvutil/tostring.h>
00007 #include <dvutil/file.h>
00008 #include <xmlwrapp/xmlwrapp.h>
00009 
00010 #include <dvxml/exception.h>
00011 #include <dvxml/noconst.h>
00012 #include <dvxml/node.h>
00013 
00014 namespace Dv {
00015 namespace Xml {
00016 
00017 /** Convenience interface to xml::document.
00018  *
00019  */
00020 class Document: public xml::document {
00021 public:
00022   /** Default ctor. */
00023   explicit Document();
00024 
00025   /** Construct a Dv::Xml::Document out of a (copy of a) Dv::Xml::Node object.
00026    * @param ref Dv::Xml::Node::Ref, a copy of which will be used as the root
00027    *   of the new Dv::Xml::Document object.
00028    * @exception Dv::Xml::Exception if node is not valid.
00029    */
00030   explicit Document(const Dv::Xml::Node::Ref& ref) throw (Dv::Xml::Exception) ;
00031 
00032   /** Parse a Dv::Xml::Document from a file
00033    * @param file containing document
00034    * @exception Dv::Xml::Exception upon any error
00035    */
00036   explicit Document(const Dv::Util::File& file) throw (Dv::Xml::Exception) ;
00037 
00038   /** Create a Dv::Xml::Document with a root labeled with given name and content. 
00039    * @param name to be used as the label of the root of the document
00040    * @param content to be used as the content of the root of the document
00041    * @exception Dv::Xml::Exception upon any error
00042    */
00043   explicit Document(const std::string& name, const std::string& content)
00044     throw (Dv::Xml::Exception);
00045 
00046   /** Create a Dv::Xml::Document with a root labeled with given name.
00047    * @param name to be used as the label of the root of the document
00048    * @exception Dv::Xml::Exception upon any error
00049    */
00050   explicit Document(const std::string& name) throw (Dv::Xml::Exception);
00051 
00052   /** Parse a Dv::Xml::Document from an array of characters .
00053    * @param pc pointer to the start of the data
00054    * @param size of the data array
00055    * @exception Dv::Xml::Exception upon any error
00056    */
00057   explicit Document(const char* pc, size_t size) throw (Dv::Xml::Exception) ;
00058 
00059   /** Create a Dv::Xml::Document by applying an XSLT stylesheet to
00060    * another Document.
00061    * @param stylesheet filename of xslt file
00062    * @param doc input document
00063    * @exception Dv::Xml::Exception upon any error
00064    */
00065   explicit Document(const std::string& stylesheet, Dv::Xml::Document& doc)
00066     throw (Dv::Xml::Exception) ;
00067 
00068   /** Destructor. */
00069   virtual ~Document();
00070 
00071   /** Parse a Dv::Xml::Document from an array of characters . The
00072    * result replaces the current contents of this document.
00073    * @param data pointer to the start of the data
00074    * @param size of the data array
00075    * @return reference to this document
00076    * @exception Dv::Xml::Exception upon any error
00077    */
00078   Dv::Xml::Document& parse(const char* data, size_t size) throw (Dv::Xml::Exception) ;
00079 
00080   /** Parse a Dv::Xml::Document from a filenm. The
00081    * result replaces the current contents of this document.
00082    * @param filenm name of file where document can be found.
00083    * @return reference to this document
00084    * @exception Dv::Xml::Exception upon any error
00085    */
00086   Dv::Xml::Document& parse(const std::string& filenm) throw (Dv::Xml::Exception) ;
00087 
00088   /** Set root.
00089    * @param ref reference to node to copy to root of this document.
00090    * @exception Dv::Xml::Exception if ref does not refer to a valid xml::node.
00091    * @sa Dv::Xml::Document::root(const Dv::Xml::Node& node)
00092    */
00093   Document& operator=(const Dv::Xml::Node::Ref& ref) throw (Dv::Xml::Exception) ;
00094 
00095   /** Set root.
00096    * @param ref reference to node that will be copied to the root of this document.
00097    * @exception Dv::Xml::Exception if node is not valid.
00098    * @sa Dv::Xml::Node
00099    */
00100   void root(const Dv::Xml::Node::Ref& ref) throw (Dv::Xml::Exception) ;
00101 
00102   /** Get root Dv::Xml::Node of Document.
00103    * @return root Dv::Xml::Node of Document.
00104    * @warning Assigning the result does \b not change the root.
00105    * Updating is possible, as in the example below.
00106    * \code
00107    * Dv::Xml::Document doc;
00108    * ..
00109    * (doc.root() >> "child" >> "grandchild")["name"] = "Pete";
00110    * \endcode
00111    */
00112   Dv::Xml::Node::Ref root() const;
00113 
00114   /** Convert to reference to root of document.
00115    * @sa Dv::Xml::Document::root
00116    */
00117   operator Dv::Xml::Node::Ref() const { return root(); }
00118 
00119   /** Get encoding of Document. Default is "ISO-8859-1". 
00120    * @return encoding of Document.
00121    */
00122   const std::string& encoding() const { return get_encoding(); }
00123 
00124   /** Set encoding of Document. 
00125    * @param enc encoding of Document
00126    * @return *this
00127    */
00128   Dv::Xml::Document& encoding(const std::string& enc) { 
00129     set_encoding(enc.c_str()); return *this; }
00130 
00131   /** Validate document w.r.t. DTD.
00132    * @param dtd url or filename of DTD, if empty, the dtd is
00133    *   assumed to have been included in the document.
00134    * @return true iff the document is valid w.r.t the DTD.
00135    */
00136   bool valid(const std::string& dtd = "");
00137 
00138   /** Select node after path from document.
00139    * @param path of the form "a/b/c"
00140    * @return node at the end of the path
00141    * @exception Dv::Xml::Exception if node is not valid.
00142    */
00143   Dv::Xml::Node::Ref select(const std::string& path) const throw (Dv::Xml::Exception) ;
00144 };
00145 
00146 }}
00147 
00148 #endif

dvxml-0.1.4 [19 September, 2003]