wxXml2
Public Member Functions | Protected Member Functions | List of all members
wxXml2Document Class Reference

This class holds XML data/document as parsed by the libxml2 parser. More...

#include <xml2.h>

Inheritance diagram for wxXml2Document:
Inheritance graph
[legend]
Collaboration diagram for wxXml2Document:
Collaboration graph
[legend]

Public Member Functions

 wxXml2Document ()
 Creates an empty document.
 
 wxXml2Document (wxXml2Node &root)
 Constructs a document and sets its root to the given node.
 
 wxXml2Document (const wxString &filename)
 Loads the given filename and parse it.
 
 wxXml2Document (xmlDoc *doc)
 Wraps the given libxml2 structure.
 
 wxXml2Document (const wxXml2Document &doc)
 Copies the given wrapper (does not imply the XML structure copy).
 
virtual ~wxXml2Document ()
 Destructor.
 
bool operator== (const wxXml2Document &doc) const
 
bool operator!= (const wxXml2Document &doc) const
 
wxXml2Documentoperator= (const wxXml2Document &doc)
 
bool Create (const wxString &version=wxS("1.0"))
 Creates a new empty XML document with the given version.
 
bool Load (wxInputStream &stream, wxString *pErr=NULL)
 Parses the data from the given wxInputStream. See Load().
 
bool Load (const wxString &filename, wxString *pErr=NULL)
 Parses XML & XHTML file and loads data.
 
int Save (wxOutputStream &stream, const wxString &encoding=wxS("UTF-8"), long flags=wxXML2DOC_USE_NATIVE_NEWLINES, int indentstep=4) const
 Saves the XML data in the given stream with the given encoding.
 
bool Save (const wxString &filename, const wxString &encoding=wxS("UTF-8"), long flags=wxXML2DOC_USE_NATIVE_NEWLINES, int indentstep=4) const
 Saves the document as XML or XHTML file in the given encoding format.
 
bool IsNonEmpty () const
 Returns TRUE if this object is wrapping a non-NULL object.
 
bool IsOk () const
 Returns TRUE if everything is okay in the XML tree structure.
 
bool IsUnlinked () const
 Returns always TRUE since documents are entities which contain links to other structures (wxXml2DTD, wxXml2Node...) but a doc is never linked with structures that are not own by itself.
 
bool IsDTDValid (wxString *err=NULL, int bUseInternal=0) const
 Checks if this document is conform to the DTD which it holds.
 
wxXml2Node GetRoot () const
 Returns the root node of the document.
 
wxXml2DTD GetDTD () const
 Returns the internal DTD associated with this document.
 
wxString GetVersion () const
 Returns version of document (may be empty).
 
wxString GetFileEncoding () const
 Returns encoding of document (may be empty).
 
xmlDoc * GetObj () const
 Returns the libxml2 underlying object.
 
void SetRoot (wxXml2Node &node)
 Changes the root of the document (deleting old one).
 
void SetDTD (wxXml2DTD &dtd)
 Sets the DTD for this document.
 
void SetStyleSheet (const wxString &xslfile)
 Creates a PI node of the type: <?xml-stylesheet type="text/xsl" href="xslfile"?> where "xslfile" is the given URI to an XSL file.
 
void SetMathMLDTD ()
 Sets the MathML DTD for this document.
 
void SetXHTMLStrictDTD ()
 Sets the XHTML DTD for this document.
 
void SetXHTMLTransitionalDTD ()
 
void SetXHTMLFrameSetDTD ()
 
- Public Member Functions inherited from wxXml2Wrapper
 wxXml2Wrapper ()
 Constructs this wrapper but not its wrapped data.
 
virtual ~wxXml2Wrapper ()
 The wxXml2Wrapper destructor will free the memory of the underlying libxml2 structure only if it is not linked to any XML tree.
 
virtual void DestroyIfUnlinked ()
 Destroys the wrapped data if it is unlinked.
 

Protected Member Functions

void Destroy ()
 Destroys the data wrapped by this class freeing its memory.
 
void SetAsEmpty ()
 Sets this element as empty: that is wrapping a NULL pointer.
 
void Copy (const wxXml2Document &doc)
 
int & GetPrivate () const
 Copies the given object.
 
- Protected Member Functions inherited from wxXml2Wrapper
void ResetRefCount ()
 
void IncRefCount ()
 
void DecRefCount ()
 
int GetRefCount () const
 
void UnwrappingOld ()
 This function should be called each time the internal pointer of the class is going to be replaced by another one.
 
void JustWrappedNew ()
 This function should be called each time the internal pointer of the class has been replaced by another one.
 

Detailed Description

This class holds XML data/document as parsed by the libxml2 parser.

Use Load and Save to perform IO on wxStream or on wxFile objects. Use the GetRoot() function to edit the contents of the XML document through wxXml2Node functions.

Constructor & Destructor Documentation

wxXml2Document::wxXml2Document ( )
inline

Creates an empty document.

Use the Create function before using it.

wxXml2Document::wxXml2Document ( wxXml2Node root)

Constructs a document and sets its root to the given node.

wxXml2Document::wxXml2Document ( const wxString &  filename)
inline

Loads the given filename and parse it.

References wxXml2Wrapper::JustWrappedNew(), and WX2XML.

wxXml2Document::wxXml2Document ( xmlDoc *  doc)
inline

Wraps the given libxml2 structure.

References wxXml2Wrapper::JustWrappedNew().

wxXml2Document::wxXml2Document ( const wxXml2Document doc)
inline

Copies the given wrapper (does not imply the XML structure copy).

virtual wxXml2Document::~wxXml2Document ( )
inlinevirtual

Destructor.

References wxXml2Wrapper::DestroyIfUnlinked().

Member Function Documentation

void wxXml2Document::Copy ( const wxXml2Document doc)
inlineprotected
bool wxXml2Document::Create ( const wxString &  version = wxS("1.0"))

Creates a new empty XML document with the given version.

References IsOk(), wxXml2Wrapper::JustWrappedNew(), and WX2XML.

void wxXml2Document::Destroy ( )
inlineprotectedvirtual

Destroys the data wrapped by this class freeing its memory.

This function should not try to update the reference count since it should have been already updated by the caller.

Implements wxXml2Wrapper.

References wxXml2Wrapper::SetAsEmpty().

wxXml2DTD wxXml2Document::GetDTD ( ) const

Returns the internal DTD associated with this document.

If no internal DTDs are associated then wxXml2EmptyDTD is returned.

Note
The DTD associated with this document could be only a simple line like: <!DOCTYPE mydtd SYSTEM "mydtd.dtd"> to intercept this case, you should use the wxXml2DTD::IsExternalReference() function.

References wxXml2DTD.

wxString wxXml2Document::GetFileEncoding ( ) const
inline

Returns encoding of document (may be empty).

Note: this is the encoding original file was saved in, not the encoding of in-memory representation!

References XML2WX.

xmlDoc* wxXml2Document::GetObj ( ) const
inline

Returns the libxml2 underlying object.

Referenced by wxXml2Node::Build(), wxXml2DTD::Create(), wxXml2Node::CreateRoot(), operator==(), and SetDTD().

int& wxXml2Document::GetPrivate ( ) const
inlineprotectedvirtual

Copies the given object.

This function should be used to implement copy constructor and assignment operators. Returns the private member of the wrapped structure.

Implements wxXml2Wrapper.

wxXml2Node wxXml2Document::GetRoot ( ) const

Returns the root node of the document.

References wxXml2Node.

Referenced by operator==(), and SetStyleSheet().

wxString wxXml2Document::GetVersion ( ) const
inline

Returns version of document (may be empty).

References XML2WX.

bool wxXml2Document::IsDTDValid ( wxString *  err = NULL,
int  bUseInternal = 0 
) const

Checks if this document is conform to the DTD which it holds.

Parameters
bUseInternalIf this parameter is set to 1, then the internal subset (m_doc->intSubset) will be used. If this parameter is set to 0, then the external subset (m_doc->extSubset) will be used. If this parameter is set to -1, then the subset will be chosen automatically (the first valid one).
Note
Libxml2 does not specify if a document can hold both an internal and an external subset. Anyway, the internal one should be the preferred choice; besides, it is the DTD returned by GetDTD() function.
bool wxXml2Document::IsNonEmpty ( ) const
inlinevirtual

Returns TRUE if this object is wrapping a non-NULL object.

Implements wxXml2Wrapper.

bool wxXml2Document::IsOk ( ) const
inline

Returns TRUE if everything is okay in the XML tree structure.

Referenced by Create(), and Load().

bool wxXml2Document::IsUnlinked ( ) const
inlinevirtual

Returns always TRUE since documents are entities which contain links to other structures (wxXml2DTD, wxXml2Node...) but a doc is never linked with structures that are not own by itself.

Implements wxXml2Wrapper.

bool wxXml2Document::Load ( wxInputStream &  stream,
wxString *  pErr = NULL 
)

Parses the data from the given wxInputStream. See Load().

References IsOk(), wxXml2Wrapper::JustWrappedNew(), and wxXml2Wrapper::UnwrappingOld().

Referenced by Load().

bool wxXml2Document::Load ( const wxString &  filename,
wxString *  pErr = NULL 
)

Parses XML & XHTML file and loads data.

Returns TRUE on success. Returns FALSE otherwise & provide an error description if the given pointer is not NULL.

References Load().

bool wxXml2Document::operator!= ( const wxXml2Document doc) const
inline
wxXml2Document& wxXml2Document::operator= ( const wxXml2Document doc)
inline
bool wxXml2Document::operator== ( const wxXml2Document doc) const

References GetObj(), and GetRoot().

int wxXml2Document::Save ( wxOutputStream &  stream,
const wxString &  encoding = wxS("UTF-8"),
long  flags = wxXML2DOC_USE_NATIVE_NEWLINES,
int  indentstep = 4 
) const

Saves the XML data in the given stream with the given encoding.

Returns the number of bytes written: -1 if there were errors.

References wxXml2::RestoreLastIndentMode(), wxXml2::SetIndentMode(), WX2XML, wxXML2DOC_USE_INDENTATION, and wxXML2DOC_USE_NATIVE_NEWLINES.

Referenced by Save().

bool wxXml2Document::Save ( const wxString &  filename,
const wxString &  encoding = wxS("UTF-8"),
long  flags = wxXML2DOC_USE_NATIVE_NEWLINES,
int  indentstep = 4 
) const

Saves the document as XML or XHTML file in the given encoding format.

Returns TRUE on success.

References Save().

void wxXml2Document::SetAsEmpty ( )
inlineprotectedvirtual

Sets this element as empty: that is wrapping a NULL pointer.

This function must not free the memory of the currently wrapped pointer: it must just reset that pointer to NULL. This function is used by DestroyIfUnlinked().

Implements wxXml2Wrapper.

void wxXml2Document::SetDTD ( wxXml2DTD dtd)

Sets the DTD for this document.

References wxXml2DTD::GetObj(), and GetObj().

Referenced by SetMathMLDTD(), SetXHTMLFrameSetDTD(), SetXHTMLStrictDTD(), and SetXHTMLTransitionalDTD().

void wxXml2Document::SetMathMLDTD ( )

Sets the MathML DTD for this document.

References SetDTD().

void wxXml2Document::SetRoot ( wxXml2Node node)

Changes the root of the document (deleting old one).

References wxXml2Node::GetObj().

void wxXml2Document::SetStyleSheet ( const wxString &  xslfile)

Creates a PI node of the type: <?xml-stylesheet type="text/xsl" href="xslfile"?> where "xslfile" is the given URI to an XSL file.

References wxXml2Node::AddPIChild(), wxXml2Node::CreateRoot(), GetRoot(), wxXml2Node::SetContent(), wxXml2BaseNode::SetType(), wxXML2_PI_NODE, and wxXml2EmptyNode.

void wxXml2Document::SetXHTMLFrameSetDTD ( )

References SetDTD().

void wxXml2Document::SetXHTMLStrictDTD ( )

Sets the XHTML DTD for this document.

References SetDTD().

void wxXml2Document::SetXHTMLTransitionalDTD ( )

References SetDTD().


The documentation for this class was generated from the following files: