Chapter 28.  XmlValue

#include <DbXml.hpp>

class DbXml::XmlValue {
public:
	XmlValue();
	XmlValue(const std::string &value);
	XmlValue(const char *value);
	XmlValue(double value);
	XmlValue(bool value);
	XmlValue(const XmlDocument &document);
	XmlValue(Type type, const std::string &value);
    XmlValue(const std::string &typeURI, 
        const std::string &typeName, 
        const std::string &value);
	XmlValue(Type type, const XmlData &data);

	virtual ~XmlValue();
	XmlValue(const XmlValue &);
	XmlValue &operator=(const XmlValue &);
	bool operator==(const XmlValue &v) const
	bool equals(const XmlValue &v) const;
	bool isNull() const;
	...
};

The XmlValue class encapsulates the value of a node in an XML document. The type of the value may be any one of the enumerated types in the XmlValue::Type enumeration. There are convenience operators for specially handling the types of STRING, DOUBLE, and BOOLEAN, as well as a constructor to make an XmlValue from XmlDocument .

The XmlValue class provides several constructors, each of which maps a C++ type or Berkeley DB XML class onto an appropriate XmlValue type. The following table lists the constructor parameter mappings.

C++ Type XmlValueType
No Parameter NONE
std::string or const char * STRING
double DOUBLE
bool BOOLEAN
XmlDocument NODE
Type and std::string String is converted to the specified type.
Type and XmlData XmlData is converted to the specified type.

The Type may be any of of the following:

XmlValue::NONEXmlValue::G_DAY
XmlValue::NODEXmlValue::G_MONTH
XmlValue::ANY_SIMPLE_TYPEXmlValue::G_MONTH_DAY
XmlValue::ANY_URIXmlValue::G_YEAR
XmlValue::BASE_64_BINARYXmlValue::G_YEAR_MONTH
XmlValue::BOOLEANXmlValue::HEX_BINARY
XmlValue::DATEXmlValue::NOTATION
XmlValue::DATE_TIMEXmlValue::QNAME
XmlValue::DATE_TIME_DURATIONXmlValue::STRING
XmlValue::DECIMALXmlValue::TIME
XmlValue::DOUBLEXmlValue::YEAR_MONTH_DURATION
XmlValue::DURATIONXmlValue::UNTYPE_ATOMIC
XmlValue::FLOATXmlValue::BINARY

The XmlValue class implements a set of methods that test if the XmlValue is of a named type. The XmlValue class also implements a set of methods that return the XmlValue as a value of a specified type. If the XmlValue is of type variable and no query context is provided when calling the test or cast methods, or no binding can be found for the variable, an exception is thrown.

In addition to type conversion, the XmlValue class also provides DOM-like navigation functions. Using these, you can retrieve features from the underlying document, such as the parent, an attribute, or a child of the current node.

This object is not thread-safe, and can only be safely used by one thread at a time in an application.

The following constructors are available for this class:

XmlValue Methods