tags:

views:

18

answers:

1

hello, is there is any way to get the value of tag by its tagname in rapidxml using c++

<?xml version=\1.0\ encoding=\latin-1\?>
<book>example</book>
<book1>example1</book1>

i need to get the book value ie example and book1 value ....we can use this doc.first_node()->value() get first node and next node but i need to is there is any way to get the value like get by name

Answer

xml_node<> *node = doc.first_node("book");
      cout <<< node->value() << "\n";
A: 

You should be able to call first_node using a node name to be matched. From the docs:

function xml_node::first_node

Synopsis

xml_node* first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; Description

Gets first child node, optionally matching node name.

Parameters

name

Name of child to find, or 0 to return first child regardless of its name; this string doesn't have to be zero-terminated if name_size is non-zero

name_size

Size of name, in characters, or 0 to have size calculated automatically from string

case_sensitive

Should name comparison be case-sensitive; non case-sensitive comparison works properly only for ASCII characters

Returns

Pointer to found child, or 0 if not found.

RapidXML does not support XPath for richer queries though.

Steve Townsend