![]() |
appkit
1.5.1
RoadNarrows Robotics Application Kit
|
XML base class. More...
#include <Xml.h>
Public Member Functions | |
| Xml (const std::string &strRootElem, const std::string &strXsiUrl="", const std::string &strXslUrl="") | |
| Initialization constructor. More... | |
| virtual | ~Xml () |
| Destructor. | |
| virtual int | loadFile (const std::string &strXmlFileName) |
| Load XML file into DOM. More... | |
| virtual int | saveFile (const std::string &strXmlFileName) |
| Save DOM to XML file. More... | |
| virtual int | createTemplateFile (const std::string &strXmlFileName, const std::string &strMajorElemName) |
| Create XML file with the given major element name under the root element. More... | |
| bool | fileExists (const std::string &strXmlFileName, bool bRequired=false) |
| Check that the XML file exists and has read/write access. More... | |
| void | setSchemaInstance (const std::string &strXsiUrl) |
| Set XML document schema instance. More... | |
| void | setStylesheet (const std::string &strXslUrl) |
| Set XML Extended Style Sheet. More... | |
| std::string | getFileName () |
| Get last load/save/create XML file name. More... | |
| bool | isModified () |
| Check if DOM has been modified since last save. More... | |
| void | setModifiedState (bool bModified) |
| Set DOM modified state. More... | |
| std::string | getErrorMsg () |
| Get last error message. More... | |
| TiXmlElement * | getMajorElem (const std::string &strMajorElemName) |
| Get the major element in the DOM. More... | |
| std::string | elemText (TiXmlElement *pElem) |
| Get element's text. More... | |
| std::string | elemAttr (TiXmlElement *pElem, const std::string &strAttrName) |
| Get element's attribute value. More... | |
| int | strToInt (const std::string &str, int &val) |
| Convert string to integer. More... | |
| int | intToStr (const int val, std::string &str, int base=10) |
| Convert integer to string. More... | |
| int | strToDouble (const std::string &str, double &val) |
| Convert string to double-precision floating-point number. More... | |
| int | doubleToStr (const double val, std::string &str) |
| Convert double to string. More... | |
Protected Member Functions | |
| virtual void | makeXmlHead () |
| Make XML document head string. More... | |
| virtual void | makeXmlTail () |
| Make XML document tail string. More... | |
| void | setErrorMsg (const char *sFmt,...) |
| Set XML error message. More... | |
Protected Attributes | |
| std::string | m_strRootElemName |
| xml top-level root element name | |
| std::string | m_strXsiUrl |
| xml schema instance | |
| std::string | m_strXslUrl |
| xml style sheet | |
| std::string | m_strXmlFileName |
| xml file path name | |
| std::string | m_strXmlHead |
| xml document head | |
| std::string | m_strXmlTail |
| xml document tail | |
| TiXmlDocument | m_xmlDoc |
| parsed xml DOM | |
| TiXmlElement * | m_pElemRoot |
| top-level root element | |
| bool | m_bModified |
| xml [not] modified | |
| char | m_bufErrMsg [256] |
| error message buffer | |
| Xml::Xml | ( | const std::string & | strRootElem, |
| const std::string & | strXsiUrl = "", |
||
| const std::string & | strXslUrl = "" |
||
| ) |
Initialization constructor.
| strRootElem | XML document top-level root element. |
| strXsiUrl | XML schema instance URL. Examples: "http://www.roadnarrows.com/xml/<em>pkg</em>/1.0/<em>name</em>.xsd" "file://<em>prefix</em>/share/<em>pkg</em>/<em>name</em>.xsd" "<em>name</em>.xsd" Default: No schema. |
| strXslUrl | XML extended stylesheet language transformation URL. Examples "http://www.roadnarrows.com/xml/<em>pkg</em>/1.0/<em>name</em>.xsl" "file://<em>prefix</em>/share/<em>pkg</em>/<em>name</em>.xsl" "<em>name</em>.xsl" Default: No stylesheet. |
Definition at line 79 of file Xml.cxx.
References m_bModified, m_bufErrMsg, and m_pElemRoot.
|
virtual |
Create XML file with the given major element name under the root element.
Any current DOM is not accessed nor altered.
| strXmlFileName | XML file path name. |
| strMajorElemName | XML major element name. A major element is an XML direct child of the root element. |
Definition at line 171 of file Xml.cxx.
References m_bufErrMsg, m_strXmlFileName, m_strXmlHead, m_strXmlTail, makeXmlHead(), makeXmlTail(), and setErrorMsg().
| int Xml::doubleToStr | ( | const double | val, |
| std::string & | str | ||
| ) |
Convert double to string.
| [in] | val | Double value. |
| [out] | str | Converted string in hex, decimal, or octal format. |
Definition at line 353 of file Xml.cxx.
Referenced by getErrorMsg().
| string Xml::elemAttr | ( | TiXmlElement * | pElem, |
| const std::string & | strAttrName | ||
| ) |
Get element's attribute value.
| pElem | Pointer to DOM element object. |
Definition at line 283 of file Xml.cxx.
Referenced by getErrorMsg().
| string Xml::elemText | ( | TiXmlElement * | pElem | ) |
Get element's text.
Leading and trailing white space is stripped.
| pElem | Pointer to DOM element object. |
<elem> text... </elem>
Definition at line 270 of file Xml.cxx.
Referenced by getErrorMsg().
| bool Xml::fileExists | ( | const std::string & | strXmlFileName, |
| bool | bRequired = false |
||
| ) |
Check that the XML file exists and has read/write access.
| strXmlFileName | XML file path name. |
| bRequired | File is [not] required to exist. |
Definition at line 210 of file Xml.cxx.
References m_bufErrMsg, and setErrorMsg().
|
inline |
Get last error message.
Definition at line 226 of file Xml.h.
References doubleToStr(), elemAttr(), elemText(), getMajorElem(), intToStr(), m_bufErrMsg, strToDouble(), and strToInt().
|
inline |
Get last load/save/create XML file name.
Definition at line 196 of file Xml.h.
References m_strXmlFileName.
| TiXmlElement * Xml::getMajorElem | ( | const std::string & | strMajorElemName | ) |
Get the major element in the DOM.
| strMajorElemName | XML major element name. A major element is an XML direct child of the root element. |
Definition at line 235 of file Xml.cxx.
References m_pElemRoot.
Referenced by getErrorMsg().
| int Xml::intToStr | ( | const int | val, |
| std::string & | str, | ||
| int | base = 10 |
||
| ) |
Convert integer to string.
| [in] | val | Integer value. |
| [out] | str | Converted string in hex, decimal, or octal format. |
| base | One of: 16 10 8. |
Definition at line 313 of file Xml.cxx.
Referenced by getErrorMsg().
|
inline |
Check if DOM has been modified since last save.
Definition at line 206 of file Xml.h.
References m_bModified.
|
virtual |
Load XML file into DOM.
| strXmlFileName | XML file path name. |
Definition at line 95 of file Xml.cxx.
References m_bufErrMsg, m_pElemRoot, m_strRootElemName, m_strXmlFileName, m_xmlDoc, setErrorMsg(), and setModifiedState().
|
protectedvirtual |
Make XML document head string.
The XML head string contains XML declarations plus the root element opening statement.
Definition at line 366 of file Xml.cxx.
References m_strRootElemName, m_strXmlHead, m_strXsiUrl, m_strXslUrl, rnr::XmlDecl, and rnr::XmlNsXsi.
Referenced by createTemplateFile().
|
protectedvirtual |
Make XML document tail string.
The XML tail string contains the root element closing statement.
Definition at line 406 of file Xml.cxx.
References m_strRootElemName, and m_strXmlTail.
Referenced by createTemplateFile().
|
virtual |
Save DOM to XML file.
| strXmlFileName | XML file path name. |
Definition at line 143 of file Xml.cxx.
References m_bufErrMsg, m_strXmlFileName, m_xmlDoc, setErrorMsg(), and setModifiedState().
|
protected |
Set XML error message.
| sFmt | Format string. |
| ... | Format variable arguments. |
Definition at line 411 of file Xml.cxx.
References m_bufErrMsg.
Referenced by createTemplateFile(), fileExists(), loadFile(), and saveFile().
|
inline |
Set DOM modified state.
| bModified | Modified state: true or false. |
Definition at line 216 of file Xml.h.
References m_bModified.
Referenced by loadFile(), and saveFile().
|
inline |
Set XML document schema instance.
| strXsiUrl | URL of schema. |
Definition at line 176 of file Xml.h.
References m_strXsiUrl.
|
inline |
Set XML Extended Style Sheet.
| strXslUrl | URL of stylesheet. |
Definition at line 186 of file Xml.h.
References m_strXslUrl.
| int Xml::strToDouble | ( | const std::string & | str, |
| double & | val | ||
| ) |
Convert string to double-precision floating-point number.
| [in] | str | String in hex, decimal, or octal format. |
| [out] | val | Converted double value. |
Definition at line 340 of file Xml.cxx.
Referenced by getErrorMsg().
| int Xml::strToInt | ( | const std::string & | str, |
| int & | val | ||
| ) |
Convert string to integer.
| [in] | str | String in hex, decimal, or octal format. |
| [out] | val | Converted integer value. |
Definition at line 298 of file Xml.cxx.
Referenced by getErrorMsg().