Dv::Xml::Document Class Reference

Convenience interface to xml::document. More...

#include <doc.h>

List of all members.

Public Member Functions

 Document ()
 Default ctor.
 Document (const Node::Ref &ref) throw (Exception)
 Construct a Dv::Xml::Document out of a (copy of a) Dv::Xml::Node object.
 Document (const Dv::Util::File &file) throw (Exception)
 Parse a Dv::Xml::Document from a file.
 Document (const std::string &name, const std::string &content) throw (Exception)
 Create a Dv::Xml::Document with a root labeled with given name and content.
 Document (const std::string &name) throw (Exception)
 Create a Dv::Xml::Document with a root labeled with given name.
 Document (const char *pc, size_t size) throw (Exception)
 Parse a Dv::Xml::Document from an array of characters .
 Document (const std::string &stylesheet, Document &doc) throw (Exception)
 Create a Dv::Xml::Document by applying an XSLT stylesheet to another Document.
virtual ~Document ()
 Destructor.
Documentparse (const char *data, size_t size) throw (Exception)
 Parse a Dv::Xml::Document from an array of characters .
Documentparse (const std::string &filenm) throw (Exception)
 Parse a Dv::Xml::Document from a filenm.
Documentoperator= (const Node::Ref &ref) throw (Exception)
 Set root.
void root (const Node::Ref &ref) throw (Exception)
 Set root.
Node::Ref root () const
 Get root Dv::Xml::Node of Document.
 operator Node::Ref () const
 Convert to reference to root of document.
const std::string & encoding () const
 Get encoding of Document.
Documentencoding (const std::string &enc)
 Set encoding of Document.
bool valid (const std::string &dtd="")
 Validate document w.r.t.
Node::Ref select (const std::string &path) const throw (Exception)
 Select node after path from document.
std::string & apply (const std::string &stylesheet, std::string &s) throw (Exception)
 Apply an XSLT stylesheet to this Document.
std::string apply (const std::string &stylesheet) throw (Exception)
 Apply an XSLT stylesheet to this Document.


Detailed Description

Convenience interface to xml::document.

Definition at line 18 of file doc.h.


Constructor & Destructor Documentation

Dv::Xml::Document::Document (  )  [explicit]

Default ctor.

Dv::Xml::Document::Document ( const Node::Ref ref  )  throw (Exception) [explicit]

Construct a Dv::Xml::Document out of a (copy of a) Dv::Xml::Node object.

Parameters:
ref Dv::Xml::Node::Ref, a copy of which will be used as the root of the new Dv::Xml::Document object.
Exceptions:
Dv::Xml::Exception if node is not valid.

Dv::Xml::Document::Document ( const Dv::Util::File file  )  throw (Exception) [explicit]

Parse a Dv::Xml::Document from a file.

Parameters:
file containing document
Exceptions:
Dv::Xml::Exception upon any error

Dv::Xml::Document::Document ( const std::string &  name,
const std::string &  content 
) throw (Exception) [explicit]

Create a Dv::Xml::Document with a root labeled with given name and content.

Parameters:
name to be used as the label of the root of the document
content to be used as the content of the root of the document
Exceptions:
Dv::Xml::Exception upon any error

Dv::Xml::Document::Document ( const std::string &  name  )  throw (Exception) [explicit]

Create a Dv::Xml::Document with a root labeled with given name.

Parameters:
name to be used as the label of the root of the document
Exceptions:
Dv::Xml::Exception upon any error

Dv::Xml::Document::Document ( const char *  pc,
size_t  size 
) throw (Exception) [explicit]

Parse a Dv::Xml::Document from an array of characters .

Parameters:
pc pointer to the start of the data
size of the data array
Exceptions:
Dv::Xml::Exception upon any error

Dv::Xml::Document::Document ( const std::string &  stylesheet,
Document doc 
) throw (Exception) [explicit]

Create a Dv::Xml::Document by applying an XSLT stylesheet to another Document.

Parameters:
stylesheet filename of xslt file
doc input document
Exceptions:
Dv::Xml::Exception upon any error
Warning:
Do not use this if the document is not xml output, as e.g. specified by an xsl directive such as
 <xsl:output method="html" encoding="ISO-8859-1" omit-xml-declaration="yes"/>
For html output, use Dv::Xml::Document::apply instead.

virtual Dv::Xml::Document::~Document (  )  [virtual]

Destructor.


Member Function Documentation

Document& Dv::Xml::Document::parse ( const char *  data,
size_t  size 
) throw (Exception)

Parse a Dv::Xml::Document from an array of characters .

The result replaces the current contents of this document.

Parameters:
data pointer to the start of the data
size of the data array
Returns:
reference to this document
Exceptions:
Dv::Xml::Exception upon any error

Document& Dv::Xml::Document::parse ( const std::string &  filenm  )  throw (Exception)

Parse a Dv::Xml::Document from a filenm.

The result replaces the current contents of this document.

Parameters:
filenm name of file where document can be found.
Returns:
reference to this document
Exceptions:
Dv::Xml::Exception upon any error

Document& Dv::Xml::Document::operator= ( const Node::Ref ref  )  throw (Exception)

Set root.

Parameters:
ref reference to node to copy to root of this document.
Exceptions:
Dv::Xml::Exception if ref does not refer to a valid xml::node.
See also:
Dv::Xml::Document::root(const Dv::Xml::Node& node)

void Dv::Xml::Document::root ( const Node::Ref ref  )  throw (Exception)

Set root.

Parameters:
ref reference to node that will be copied to the root of this document.
Exceptions:
Dv::Xml::Exception if node is not valid.
See also:
Dv::Xml::Node

Node::Ref Dv::Xml::Document::root (  )  const

Get root Dv::Xml::Node of Document.

Returns:
root Dv::Xml::Node of Document.
Warning:
Assigning the result does not change the root. Updating is possible, as in the example below.
 Dv::Xml::Document doc;
 ..
 (doc.root() >> "child" >> "grandchild")["name"] = "Pete";

Referenced by operator Node::Ref().

Dv::Xml::Document::operator Node::Ref (  )  const [inline]

Convert to reference to root of document.

See also:
Dv::Xml::Document::root

Definition at line 119 of file doc.h.

References root().

const std::string& Dv::Xml::Document::encoding (  )  const [inline]

Get encoding of Document.

Default is "ISO-8859-1".

Returns:
encoding of Document.

Definition at line 124 of file doc.h.

Document& Dv::Xml::Document::encoding ( const std::string &  enc  )  [inline]

Set encoding of Document.

Parameters:
enc encoding of Document
Returns:
*this

Definition at line 130 of file doc.h.

bool Dv::Xml::Document::valid ( const std::string &  dtd = ""  ) 

Validate document w.r.t.

DTD.

Parameters:
dtd url or filename of DTD, if empty, the dtd is assumed to have been included in the document.
Returns:
true iff the document is valid w.r.t the DTD.

Node::Ref Dv::Xml::Document::select ( const std::string &  path  )  const throw (Exception)

Select node after path from document.

Parameters:
path of the form "a/b/c"
Returns:
node at the end of the path
Exceptions:
Dv::Xml::Exception if node is not valid.

std::string& Dv::Xml::Document::apply ( const std::string &  stylesheet,
std::string &  s 
) throw (Exception)

Apply an XSLT stylesheet to this Document.

The result is immediately serialised in a string (useful e.g. when the "omit-xml-declaration" option is used.

Parameters:
stylesheet filename of xslt file
s string that will contain the result of the XSL transform.
Returns:
s
Exceptions:
Dv::Xml::Exception upon any error
Warning:
This is function properly takes into account directives such as
 <xsl:output method="html" encoding="ISO-8859-1" omit-xml-declaration="yes"/>
Do not look for a simple way to send output of an xslt transformation to a stream. There is none (en neither is there in xmlwrapp, xml++, .. ). The reason is probably that libxslt only provides output to FILE* using xsltSaveResultTo.. functions. And I don't know of an easy way to link std::ostream objects to FILE*'s.

std::string Dv::Xml::Document::apply ( const std::string &  stylesheet  )  throw (Exception) [inline]

Apply an XSLT stylesheet to this Document.

The result is immediately serialised in a string (useful e.g. when the "omit-xml-declaration" option is used.

Parameters:
stylesheet filename of xslt file
Returns:
string that containing the result of the XSL transform.
Exceptions:
Dv::Xml::Exception upon any error
Warning:
This is function properly takes into account directives such as
 <xsl:output method="html" encoding="ISO-8859-1" omit-xml-declaration="yes"/>

Definition at line 178 of file doc.h.


The documentation for this class was generated from the following file:
dvxml-0.1.7 [ 7 January, 2008]