Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
XmlTools Class Reference

#include <XmlTools.hpp>

+ Collaboration diagram for XmlTools:

Classes

class  Finalizer
 

Static Public Member Functions

static XSD_DOM_AUTO_PTR< xercesc::DOMDocument > ReadXmlFile (const std::string &rFileName, const ::xsd::cxx::tree::properties< char > &rProps, bool validate=true)
 
static void Finalize ()
 
static XSD_DOM_AUTO_PTR< xercesc::DOMDocument > ReadFileToDomDocument (const std::string &rFileName, ::xsd::cxx::xml::error_handler< char > &rErrorHandler, const ::xsd::cxx::tree::properties< char > &rProps, bool validate=true)
 
static void PrintNode (const std::string &rMsg, xercesc::DOMNode *pNode, bool showChildren=false)
 
static xercesc::DOMElement * SetNamespace (xercesc::DOMDocument *pDocument, xercesc::DOMElement *pElement, const std::string &rNamespace)
 
static xercesc::DOMElement * SetNamespace (xercesc::DOMDocument *pDocument, xercesc::DOMElement *pElement, const XMLCh *pNamespace)
 
static void WrapContentInElement (xercesc::DOMDocument *pDocument, xercesc::DOMElement *pElement, const XMLCh *pNewElementLocalName)
 
static std::vector< xercesc::DOMElement * > GetChildElements (const xercesc::DOMElement *pElement)
 
static std::vector< xercesc::DOMElement * > FindElements (const xercesc::DOMElement *pContextElement, const std::string &rPath)
 
static void FindElements (const xercesc::DOMElement *pContextElement, const std::vector< std::string > &rNames, std::vector< xercesc::DOMElement * > &rResults, unsigned depth=0)
 
static std::string EscapeSpaces (const std::string &rPath)
 

Detailed Description

A class of utility methods for processing XML files, using Xerces and CodeSynthesis XSD.

Definition at line 72 of file XmlTools.hpp.

Member Function Documentation

◆ EscapeSpaces()

std::string XmlTools::EscapeSpaces ( const std::string &  rPath)
static

Helper method for URL-escaping spaces in file paths, to avoid confusing Xerces regarding schema locations. Note that this is a very specific fix: it doesn't do general URL-escaping.

Parameters
rPaththe path to escape
Returns
path with spaces escaped

Definition at line 442 of file XmlTools.cpp.

Referenced by HeartConfig::ReadFile().

◆ Finalize()

void XmlTools::Finalize ( )
static

Must be called after you have finished working with a document returned by the ReadXmlFile methods. An alternative is to instantiate

just before calling ReadXmlFile, provided that you will do all your processing within that scope. The finalizer object will call Finalize in its destructor.

Definition at line 103 of file XmlTools.cpp.

Referenced by XmlTools::Finalizer::~Finalizer(), and ReadXmlFile().

◆ FindElements() [1/2]

std::vector< xercesc::DOMElement * > XmlTools::FindElements ( const xercesc::DOMElement *  pContextElement,
const std::string &  rPath 
)
static
Returns
all elements matching the given path from this context element.
Parameters
pContextElementthe root element to search from
rPathwhere to search. This should be a '/'-separated path of element names.

Definition at line 384 of file XmlTools.cpp.

References FindElements().

Referenced by XmlTransforms::CheckForIluPreconditioner(), FindElements(), FindElements(), XmlTransforms::MoveConductivityHeterogeneities(), XmlTransforms::SetDefaultVisualizer(), XmlTransforms::TransformArchiveDirectory(), and XmlTransforms::TransformIonicModelDefinitions().

◆ FindElements() [2/2]

void XmlTools::FindElements ( const xercesc::DOMElement *  pContextElement,
const std::vector< std::string > &  rNames,
std::vector< xercesc::DOMElement * > &  rResults,
unsigned  depth = 0 
)
static

Find all elements matching the given path from this context element.

Parameters
pContextElementthe root element to search from
rNamesa list of element names, the first of which is looked for as children of pContextElement; the next as children of those, etc.
rResultsvector to be filled in with matching elements
depthfor managing recursion; should not be provided by users

Definition at line 359 of file XmlTools.cpp.

References FindElements().

◆ GetChildElements()

std::vector< xercesc::DOMElement * > XmlTools::GetChildElements ( const xercesc::DOMElement *  pElement)
static
Returns
all the child elements of the given element.
Parameters
pElementthe parent element

Definition at line 343 of file XmlTools.cpp.

Referenced by SetNamespace().

◆ PrintNode()

void XmlTools::PrintNode ( const std::string &  rMsg,
xercesc::DOMNode *  pNode,
bool  showChildren = false 
)
static

Display key info about an XML node for debugging.

Parameters
rMsgmessage to prepend to the report
pNodethe node to display
showChildrenwhether to recursive display the node's children

Definition at line 262 of file XmlTools.cpp.

References PrintNode().

Referenced by PrintNode().

◆ ReadFileToDomDocument()

XSD_DOM_AUTO_PTR< xercesc::DOMDocument > XmlTools::ReadFileToDomDocument ( const std::string &  rFileName,
::xsd::cxx::xml::error_handler< char > &  rErrorHandler,
const ::xsd::cxx::tree::properties< char > &  rProps,
bool  validate = true 
)
static

Read an XML file into a DOM document. Useful for figuring out what version of the parameters file we're dealing with, so we can construct the right version of the object model.

Based on http://wiki.codesynthesis.com/Tree/FAQ#How_do_I_parse_an_XML_document_to_a_Xerces-C.2B.2B_DOM_document.3F

Requires the Xerces runtime to have been initialised.

Parameters
rFileNamethe file to read
rErrorHandlerhandler for any parsing errors
rPropsproperties that specify fixed schema locations, if wanted
validatewhether to perform schema validation
Returns
Xerces convenience object

Definition at line 125 of file XmlTools.cpp.

Referenced by ReadXmlFile().

◆ ReadXmlFile()

XSD_DOM_AUTO_PTR< xercesc::DOMDocument > XmlTools::ReadXmlFile ( const std::string &  rFileName,
const ::xsd::cxx::tree::properties< char > &  rProps,
bool  validate = true 
)
static

Read an XML file into a DOM document, turning parsing errors into Chaste Exceptions. Handles initialising the Xerces runtime.

Parameters
rFileNamethe file to read
rPropsproperties that specify fixed schema locations, if wanted
validatewhether to perform schema validation
Returns
Xerces convenience object

Definition at line 53 of file XmlTools.cpp.

References EXCEPTION, Finalize(), and ReadFileToDomDocument().

Referenced by HeartConfig::ReadFile().

◆ SetNamespace() [1/2]

xercesc::DOMElement * XmlTools::SetNamespace ( xercesc::DOMDocument *  pDocument,
xercesc::DOMElement *  pElement,
const std::string &  rNamespace 
)
static

Fake having a namespace in older configuration files, by setting the namespace on each element in a tree.

Based on http://wiki.codesynthesis.com/Tree/FAQ#How_do_I_parse_an_XML_document_that_is_missing_namespace_information.3F

Parameters
pDocumentthe DOM document containing the tree to be transformed
pElementthe root of the tree to be transformed
rNamespacethe namespace to put elements in
Returns
Xerces element

Definition at line 335 of file XmlTools.cpp.

References SetNamespace().

Referenced by HeartConfig::ReadFile(), SetNamespace(), and SetNamespace().

◆ SetNamespace() [2/2]

xercesc::DOMElement * XmlTools::SetNamespace ( xercesc::DOMDocument *  pDocument,
xercesc::DOMElement *  pElement,
const XMLCh *  pNamespace 
)
static

Fake having a namespace in older configuration files, by setting the namespace on each element in a tree.

Based on http://wiki.codesynthesis.com/Tree/FAQ#How_do_I_parse_an_XML_document_that_is_missing_namespace_information.3F

Parameters
pDocumentthe DOM document containing the tree to be transformed
pElementthe root of the tree to be transformed
pNamespacethe namespace to put elements in
Returns
Xerces element

Definition at line 291 of file XmlTools.cpp.

References GetChildElements(), and SetNamespace().

◆ WrapContentInElement()

void XmlTools::WrapContentInElement ( xercesc::DOMDocument *  pDocument,
xercesc::DOMElement *  pElement,
const XMLCh *  pNewElementLocalName 
)
static

Wrap the content (children) of an element within a new element. The new element becomes the sole child of the original element.

Note
Doesn't transfer attributes.
Parameters
pDocumentthe DOM document containing the tree to be transformed
pElementthe element whose content is to be wrapped
pNewElementLocalNamethe local name (i.e. without namespace prefix) of the wrapping element (the namespace of pElement will be used).

Definition at line 409 of file XmlTools.cpp.

Referenced by XmlTransforms::TransformIonicModelDefinitions().


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