Examining reader lock's current node

std::string type=rlock->type();
	
std::string name=rlock->name();
	
std::string prefix=rlock->prefix();
	
std::string uri=rlock->uri();
	
std::string path=rlock->path();
	

type() returns the type of the current node, as a string. element_node gets returned when the current node is an XML element node, text_node gets returned when the current node is a text node. The string corresponds directly to the xmlElementType values from libxml, in lowercase and without the XML_ prefix. An empty string gets returned if the reader lock is not positioned on a node.

name() returns the name of the current node when it is an element_node. Some other node types also use name() (processing instructions, pi_nodes, have the processor name, here).

prefix() and uri() give the element node's namespace prefix and URI, or an empty string if the element node is not in any namespace.

path() returns the XPath to the current node, starting with the document's root.

std::string value;

value=rlock->get_attribute("style");

x::uriimpl ns;

value=rlock->get_attribute("style", ns);

value=rlock->get_any_attribute("style");

std::set<x::doc::base::attribute> attributes;
rlock->get_all_attributes(attributes);

get_attribute() returns the value of the given attribute in the null XML namespace, if the reader lock is positioned on an element node, and the given un-namespaced attribute exists. An empty string gets returned in all other situations.

A second parameter to get_attribute() gives an explicit x namespace for the attribute's name, and returns the value of the attribute in the referenced namespace. The namespace can be specified either as x::uriimpl or as a literal string.

get_any_attribute() retrieves the value of the specified attribute in any namespace. get_all_attributes() enumerates the current element's node attributes, and places them into a set of x::xml::doc::base::attributes. This class contains two string members:

attrname

The attribute's name.

attrnamespace

The attribute's namespace. An empty string specifies an attribute that's not in any namespace.

std::string text=rlock->get_text();

std::string lang=rlock->get_lang();

bool flag=rlock->is_text();

bool flag=rlock->is_blank();

int flag=rlock->get_space_preserve();

std::string uri=rlock->get_base();

get_text() returns the text representation of the current node. For comment nodes, get_text() returns the contents of the comment. For processing instruction nodes, get_text() returns the processing instructions. get_lang() returns the current's node declare language (the xml:lang attribute, if it's defined, an empty string otherwise). is_text() returns true if the current node is a text node. is_blank() returns true if the current node is a text node, and it is empty.

get_space_preserve() returns 1 if the node or one of its parent node has an xml:space attribute that's set to preserve, 0 if it's default, and negative if xml:space is not declared for the current node. get_base() returns the node's base URI, as defined in RFC 2396 section 5.1.1.

rlock->save_file("filename.xml");
	
std::string s;
	
rlock->save_to(std::back_insert_iterator<std::string>(s));

save_file() saves the XML document into a file. save_to() writes the XML document into an output iterator. save_to() returns the new value of the output iterator.

Both save_file() and save_to() take an optional second bool parameter. Setting it to true formats the XML document with whitespace indentation.

Note

save_file() writes the XML document into filename.tmp, and renames it to the given filename.