XML Namespace Reference

Typedefs

using Document = rapidxml::xml_document< char >
 
using Node = rapidxml::xml_node< char >
 
using NodeType = rapidxml::node_type
 
using Attribute = rapidxml::xml_attribute< char >
 

Functions

NodeinsertDeclaration (Document &doc)
 Add a declaration to the document if there isn't one already. More...
 
bool deserialize (Document &doc, char *content)
 De-serialise XML text into a document. More...
 
static bool deserialize (Document &doc, String &content)
 
bool deserialize (Document &doc, const FlashString &content)
 
size_t serialize (const Node &node, String &buffer, bool pretty=false)
 Serialize XML text and append to string buffer. More...
 
String serialize (const Node &node, bool pretty=false)
 
size_t serialize (const Node &node, Print &out, bool pretty=false)
 
static size_t serialize (const Node &node, Print *out, bool pretty=false)
 
NodeappendNode (Node *parent, const char *name, const char *value=nullptr, size_t name_size=0, size_t value_size=0)
 Append a child element with optional value. More...
 
static NodeappendNode (Node *parent, const String &name, const String &value=nullptr)
 
NodeappendNode (Node *parent, const String &name, const FlashString &value)
 
template<typename TString , typename TValue >
NodeappendNode (Node *parent, const TString &name, const TValue &value)
 
AttributeappendAttribute (Node *node, const char *name, const char *value, size_t name_size=0, size_t value_size=0)
 Append an attribute. More...
 
static AttributeappendAttribute (Node *node, const String &name, const String &value)
 
template<typename TString , typename TValue >
AttributeappendAttribute (Node *node, const TString &name, const TValue &value)
 
Gets child node by relative path
Parameters
doc
pathNode path using slash as separator
nsOptional namespace
Return values
Node*nullptr if none is found

Leading/trailing separators are not permitted.

NodegetNode (Node *node, const char *path, const char *ns, size_t ns_len=0)
 
NodegetNode (Node *node, const String &path, const String &ns=nullptr)
 
Gets node from a document by path
Parameters
doc
pathNode path using slash as separator
nsOptional namespace
Return values
Node*nullptr if none is found

Leading separator is important: if present, search starts at root node. If omitted, first element must match the root node name.

Trailing separator is not allowed.

Example 1: /s:Body/u:GetContentResponse Will search for s:Body node that is a child of the root node. The node u:GetContentResponse should be child of the s:Body node

Example 2: s:Envelope/s:Body/u:GetContentResponse Will search for s:Body node that is a child of the root node named s:Envelope. The node u:GetContentResponse should be child of the s:Body node

NodegetNode (const Document &doc, const char *path, const char *ns=nullptr, size_t ns_len=0)
 
NodegetNode (const Document &doc, const String &path, const String &ns=nullptr)
 
Get node value
Parameters
node
name
name_size
Return values
Stringinvalid if node or name not found
String getValue (const Node *node, const char *name, size_t name_size, const char *ns=nullptr, size_t ns_size=0)
 
String getValue (const Node *node, const char *name, const char *ns=nullptr)
 
String getValue (const Node *node, const String &name, const String &ns=nullptr)
 
Get attribute value
Parameters
node
name
name_size
Return values
Stringinvalid if node or name not found
String getAttribute (const Node *node, const char *name, size_t name_size)
 
String getAttribute (const Node *node, const char *name)
 
String getAttribute (const Node *node, const String &name)
 

Typedef Documentation

◆ Attribute

using XML::Attribute = typedef rapidxml::xml_attribute<char>

◆ Document

using XML::Document = typedef rapidxml::xml_document<char>

◆ Node

using XML::Node = typedef rapidxml::xml_node<char>

◆ NodeType

using XML::NodeType = typedef rapidxml::node_type

Function Documentation

◆ appendAttribute() [1/3]

Attribute* XML::appendAttribute ( Node node,
const char *  name,
const char *  value,
size_t  name_size = 0,
size_t  value_size = 0 
)

Append an attribute.

Parameters
parentNode to append child to
nameName of attribute (copy taken)
valueValue string (copy taken)
Attribute*New attribute

◆ appendAttribute() [2/3]

static Attribute* XML::appendAttribute ( Node node,
const String name,
const String value 
)
inlinestatic

◆ appendAttribute() [3/3]

template<typename TString , typename TValue >
Attribute* XML::appendAttribute ( Node node,
const TString &  name,
const TValue &  value 
)

◆ appendNode() [1/4]

Node* XML::appendNode ( Node parent,
const char *  name,
const char *  value = nullptr,
size_t  name_size = 0,
size_t  value_size = 0 
)

Append a child element with optional value.

Parameters
parentNode to append child to
nameName of child node (copy taken)
valueOptional node value (copy taken)
Return values
Node*Child node
Note
If provide, sizes do not include nul-terminator Node MUST already be added to the document tree

◆ appendNode() [2/4]

Node* XML::appendNode ( Node parent,
const String name,
const FlashString value 
)

◆ appendNode() [3/4]

static Node* XML::appendNode ( Node parent,
const String name,
const String value = nullptr 
)
inlinestatic

◆ appendNode() [4/4]

template<typename TString , typename TValue >
Node* XML::appendNode ( Node parent,
const TString &  name,
const TValue &  value 
)

◆ deserialize() [1/3]

bool XML::deserialize ( Document doc,
char *  content 
)

De-serialise XML text into a document.

Return values
boolfalse on parse error
Note
Document maintains references to content so MUST stay in scope for lifetime of doc, or until doc.clear() is called

◆ deserialize() [2/3]

bool XML::deserialize ( Document doc,
const FlashString content 
)

◆ deserialize() [3/3]

static bool XML::deserialize ( Document doc,
String content 
)
inlinestatic

◆ getAttribute() [1/3]

String XML::getAttribute ( const Node node,
const char *  name 
)
inline

◆ getAttribute() [2/3]

String XML::getAttribute ( const Node node,
const char *  name,
size_t  name_size 
)

◆ getAttribute() [3/3]

String XML::getAttribute ( const Node node,
const String name 
)
inline

◆ getNode() [1/4]

Node* XML::getNode ( const Document doc,
const char *  path,
const char *  ns = nullptr,
size_t  ns_len = 0 
)

◆ getNode() [2/4]

Node* XML::getNode ( const Document doc,
const String path,
const String ns = nullptr 
)
inline

◆ getNode() [3/4]

Node* XML::getNode ( Node node,
const char *  path,
const char *  ns,
size_t  ns_len = 0 
)

◆ getNode() [4/4]

Node* XML::getNode ( Node node,
const String path,
const String ns = nullptr 
)
inline

◆ getValue() [1/3]

String XML::getValue ( const Node node,
const char *  name,
const char *  ns = nullptr 
)
inline

◆ getValue() [2/3]

String XML::getValue ( const Node node,
const char *  name,
size_t  name_size,
const char *  ns = nullptr,
size_t  ns_size = 0 
)

◆ getValue() [3/3]

String XML::getValue ( const Node node,
const String name,
const String ns = nullptr 
)
inline

◆ insertDeclaration()

Node* XML::insertDeclaration ( Document doc)

Add a declaration to the document if there isn't one already.

Note
By default, declarations are included when parsed during de-serialisation. If you need one in the output serialisation, call this function. (We're talking about the "<?xml version="1.0" ?>" at the start)

◆ serialize() [1/4]

String XML::serialize ( const Node node,
bool  pretty = false 
)

◆ serialize() [2/4]

size_t XML::serialize ( const Node node,
Print out,
bool  pretty = false 
)

◆ serialize() [3/4]

static size_t XML::serialize ( const Node node,
Print out,
bool  pretty = false 
)
inlinestatic

◆ serialize() [4/4]

size_t XML::serialize ( const Node node,
String buffer,
bool  pretty = false 
)

Serialize XML text and append to string buffer.

Return values
size_tnumber of characters written