59 #include <libxml/tree.h>
71 xmlnode_ = xmlNewNode(0,
reinterpret_cast<const xmlChar*
>(
"blank"));
72 if (!xmlnode_)
throw std::bad_alloc();
79 xmlnode_ = xmlCopyNode(other.
xmlnode_, 2);
80 if (!xmlnode_)
throw std::bad_alloc();
87 {
if (owner_ && xmlnode_) xmlFreeNode(xmlnode_); }
102 pimpl_ =
new pimpl(0);
131 if (
this != &other) {
141 return pimpl_->xmlnode_;
145 return xml::ns(libxml2RawNamespace);
153 xmlNodePtr x =
static_cast<xmlNodePtr
>(
node);
156 pimpl_->owner_ =
false;
157 pimpl_->xmlnode_ = x;
162 pimpl_->xmlnode_->properties,
169 pimpl_->xmlnode_->properties,
190 if ( (!name) || (!
value))
192 "insert must not be NULL");
196 bool only_whitespaces =
true;
197 const char * current = name;
198 while (*current !=
'\0') {
199 if (memchr(
" \t\n\r", *current, 4) ==
NULL) {
200 only_whitespaces =
false;
205 if (only_whitespaces)
207 "of only whitespace characters");
210 const char *
column = strchr(name,
':');
218 if (*(
column + 1) ==
'\0')
221 throw xml::exception(
"an attribute may not have a default namespace");
224 xmlNsPtr resolved_ns = xmlSearchNs(pimpl_->xmlnode_->doc,
226 reinterpret_cast<const xmlChar*
>(prefix.c_str()));
230 if (xmlSetNsProp(pimpl_->xmlnode_,
232 reinterpret_cast<const xmlChar*
>(
column + 1),
233 reinterpret_cast<const xmlChar*
>(
value)) ==
NULL)
239 if (xmlSetProp(pimpl_->xmlnode_,
240 reinterpret_cast<const xmlChar*
>(name),
241 reinterpret_cast<const xmlChar*
>(
value)) ==
NULL)
248 throw xml::exception(
"cannot specify both a qualified name and a namespace");
252 if (xmlSetProp(pimpl_->xmlnode_,
253 reinterpret_cast<const xmlChar*
>(name),
254 reinterpret_cast<const xmlChar*
>(
value)) ==
NULL)
260 throw xml::exception(
"an attribute may not have a default namespace");
263 if (xmlSetNsProp(pimpl_->xmlnode_,
264 reinterpret_cast<xmlNsPtr
>(nspace->
unsafe_ns_),
265 reinterpret_cast<const xmlChar*
>(name),
266 reinterpret_cast<const xmlChar*
>(
value)) ==
NULL)
273 xmlNsPtr resolved_ns = xmlSearchNsByHref(pimpl_->xmlnode_->doc,
275 reinterpret_cast<const xmlChar*
>(nspace->
get_uri()));
278 "cannot resolve namespace");
280 if (xmlSetNsProp(pimpl_->xmlnode_,
282 reinterpret_cast<const xmlChar*
>(name),
283 reinterpret_cast<const xmlChar*
>(
value)) ==
NULL)
290 xmlAttrPtr prop =
find_prop(pimpl_->xmlnode_, name, nspace);
292 return iterator(pimpl_->xmlnode_, prop,
false,
true);
296 return iterator(pimpl_->xmlnode_, dtd_prop,
true,
true);
302 const ns *nspace)
const {
303 xmlAttrPtr prop =
find_prop(pimpl_->xmlnode_, name, nspace);
320 "not initialized or belongs to another node attributes");
323 if (to_erase == end())
329 xmlAttrPtr prop_to_erase =
static_cast<xmlAttrPtr
>(to_erase.
pimpl_->
get()->
prop_);
332 xmlUnsetNsProp(pimpl_->xmlnode_, prop_to_erase->ns, prop_to_erase->name);
341 const char *
column = strchr(name,
':');
347 if (*(
column + 1) ==
'\0')
351 xmlNsPtr resolved_ns = xmlSearchNs(pimpl_->xmlnode_->doc,
353 reinterpret_cast<const xmlChar*
>(prefix.c_str()));
357 if (xmlUnsetNsProp(pimpl_->xmlnode_,
359 reinterpret_cast<const xmlChar*
>(
column + 1)) == 0)
367 while (att !=
NULL) {
369 xmlUnlinkNode(
reinterpret_cast<xmlNodePtr
>(att));
381 if (xmlUnsetProp(pimpl_->xmlnode_,
382 reinterpret_cast<const xmlChar*
>(name)) == 0)
388 if (xmlUnsetNsProp(pimpl_->xmlnode_,
389 reinterpret_cast<xmlNsPtr
>(nspace->
unsafe_ns_),
390 reinterpret_cast<const xmlChar*
>(name)) == 0)
396 xmlNsPtr resolved_ns = xmlSearchNsByHref(pimpl_->xmlnode_->doc,
398 reinterpret_cast<const xmlChar*
>(nspace->
get_uri()));
406 while (xmlUnsetNsProp(pimpl_->xmlnode_,
408 reinterpret_cast<const xmlChar*
>(name)) == 0)
414 return pimpl_->xmlnode_->properties == 0;
420 xmlAttrPtr prop = pimpl_->xmlnode_->properties;
421 while (prop != 0) { ++
count; prop = prop->next; }
427 bool operator() (
const xmlAttrPtr & lhs,
const xmlAttrPtr & rhs)
const {
428 return strcmp(
reinterpret_cast<const char *
>(lhs->name),
429 reinterpret_cast<const char *
>(rhs->name)) < 0;
433 std::list<xmlAttrPtr> attrs;
434 xmlAttrPtr prop = pimpl_->xmlnode_->properties;
438 attrs.push_back(prop);
446 xmlAttrPtr cur =
NULL;
449 for (std::list<xmlAttrPtr>::const_iterator k = attrs.begin();
450 k != attrs.end(); ++k) {
454 pimpl_->xmlnode_->properties = cur;
This file defines the xml::ait_impl class.
const char * kInsertError
This file contains the definition of the xml::attributes class.
bool is_default(void) const
Test if the attribute is default.
Const Iterator class for accessing attribute pairs.
Iterator class for accessing attribute pairs.
The xml::attributes class is used to access all the attributes of one xml::node.
std::size_t size_type
size type
size_type size(void) const
Find out how many attributes there are in this xml::attributes object.
iterator erase(iterator to_erase)
Erase the attribute that is pointed to by the given iterator.
void swap(attributes &other)
Swap this xml::attributes object with another one.
attributes(void)
Create a new xml::attributes object with no attributes.
iterator find(const char *name, const ns *nspace=NULL)
Find the attribute with the given name and namespace.
iterator begin(void)
Get an iterator that points to the first attribute.
static xml::ns createUnsafeNamespace(void *libxml2RawNamespace)
static void * getUnsafeNamespacePointer(const xml::ns &name_space)
void sort(void)
Sorts the attributes in place.
attributes & operator=(const attributes &other)
Copy the given xml::attributes object into this one.
iterator end(void)
Get an iterator that points one past the the last attribute.
void set_data(void *node)
bool empty(void) const
Find out if there are any attributes in this xml::attributes object.
virtual ~attributes(void)
Clean up after a xml::attributes object.
void insert(const char *name, const char *value, const ns *nspace=NULL)
Add an attribute to the attributes list.
This exception class is thrown by xmlwrapp for all runtime XML-related errors along with the xml::par...
attributes::attr * get(void)
The xml::node class is used to hold information about one XML node.
The xml::ns class is used to access and handle namespaces of nodes and attributes.
const char * get_prefix(void) const
Get the namespace prefix.
const char * get_uri(void) const
Get the namespace URI.
bool is_safe(void) const
Check if the object is safe i.e.
bool is_void(void) const
If a node or an attribute has no namespace, then a namespace with empty prefix and empty URI is retur...
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static const char * column
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
This file contains the definition of the xml::exception class.
const GenericPointer< typename T::ValueType > T2 value
int strcmp(const char *str1, const char *str2)
phantom_attr * find_default_prop(xmlNodePtr xmlnode, const char *name, const ns *nspace)
xmlAttrPtr find_prop(xmlNodePtr xmlnode, const char *name, const ns *nspace)
pimpl(const pimpl &other)
pimpl & operator=(const pimpl &)