59 #include <libxml/tree.h>
60 #include <libxml/valid.h>
66 const char*
kDerefError =
"dereferencing non initialised or out of range iterator";
67 const char*
kRefError =
"referencing non initialised or out of range iterator";
68 const char*
kAdvError =
"advancing non initialised or out of range iterator";
78 from_find_(from_find) {
83 from_find_(from_find) {
89 from_find_(other.from_find_)
107 "produced by find(...) methods");
131 pimpl_ =
new ait_impl(0,
static_cast<xmlAttrPtr
>(0),
false);
135 bool def_prop,
bool from_find) {
141 static_cast<xmlAttrPtr
>(prop), from_find);
199 pimpl_ =
new ait_impl(0,
static_cast<xmlAttrPtr
>(0),
false);
210 static_cast<xmlAttrPtr
>(prop), from_find);
277 xmlnode_(other.xmlnode_), prop_(other.prop_),
278 phantom_prop_(other.phantom_prop_), value_(other.value_)
291 value_.swap(other.
value_);
299 phantom_prop_ = prop;
308 if (!xmlnode_)
return NULL;
309 if (prop_)
return prop_;
313 return static_cast<phantom_attr*
>(phantom_prop_)->prop_;
324 bool xml::attributes::attr::operator==
326 return normalize() == other.normalize();
330 if (phantom_prop_ && (!
static_cast<phantom_attr*
>(phantom_prop_)->prop_))
337 xmlAttributePtr dprop =
static_cast<phantom_attr*
>(phantom_prop_)->def_prop_;
340 return reinterpret_cast<const char*
>(dprop->name);
343 const xmlChar * name =
static_cast<xmlAttrPtr
>(prop_)->name;
344 return reinterpret_cast<const char*
>(name);
346 const xmlChar * name =
static_cast<phantom_attr*
>(phantom_prop_)->prop_->name;
347 return reinterpret_cast<const char*
>(name);
352 xmlAttributePtr dprop =
static_cast<phantom_attr*
>(phantom_prop_)->def_prop_;
355 if (dprop->defaultValue)
356 return reinterpret_cast<const char*
>(dprop->defaultValue);
362 tmpstr = xmlNodeListGetString(
reinterpret_cast<xmlNodePtr
>(xmlnode_)->doc,
363 reinterpret_cast<xmlAttrPtr
>(prop_)->children,
367 tmpstr = xmlNodeListGetString(
reinterpret_cast<xmlNodePtr
>(xmlnode_)->doc,
368 reinterpret_cast<phantom_attr*
>(phantom_prop_)->prop_->children,
375 value_.assign(
reinterpret_cast<const char*
>(tmpstr));
376 return value_.c_str();
383 definition =
static_cast<xmlNs*
>(resolve_default_attr_ns());
386 xmlAttrPtr prop =
reinterpret_cast<xmlAttrPtr
>(prop_);
388 prop =
reinterpret_cast<phantom_attr*
>(phantom_prop_)->prop_;
389 definition = prop->ns;
394 ?
xml::ns(
reinterpret_cast<const char*
>(definition->prefix),
395 reinterpret_cast<const char*
>(definition->href))
408 "resolving non-default attribute namespace");
410 xmlAttributePtr dprop =
static_cast<phantom_attr*
>(phantom_prop_)->def_prop_;
413 xmlNs * definition(xmlSearchNs(
NULL,
reinterpret_cast<xmlNode*
>(xmlnode_),
417 throw xml::exception(
"cannot resolve default attribute namespace");
426 xmlNs * definition =
static_cast<xmlNs*
>(resolve_default_attr_ns());
427 xmlAttributePtr dprop =
static_cast<phantom_attr*
>(phantom_prop_)->def_prop_;
430 xmlAttrPtr new_attr = xmlSetNsProp(
reinterpret_cast<xmlNode*
>(xmlnode_),
433 dprop->defaultValue);
435 throw xml::exception(
"cannot convert default attribute into a regular one");
439 static_cast<phantom_attr*
>(phantom_prop_)->prop_ = new_attr;
445 xmlAttrPtr prop =
reinterpret_cast<xmlAttrPtr
>(normalize());
446 xmlSetNsProp(
reinterpret_cast<xmlNode*
>(xmlnode_),
449 reinterpret_cast<const xmlChar*
>(
value));
455 xmlAttrPtr prop =
reinterpret_cast<xmlAttrPtr
>(normalize());
460 if (!prefix || prefix[0] ==
'\0') {
466 xmlAttrPtr prop =
reinterpret_cast<xmlAttrPtr
>(normalize());
467 xmlNs * definition(xmlSearchNs(
NULL,
reinterpret_cast<xmlNode*
>(xmlnode_),
468 reinterpret_cast<const xmlChar*
>(prefix)));
471 prop->ns = definition;
482 xmlAttrPtr prop =
reinterpret_cast<xmlAttrPtr
>(normalize());
489 if (prefix[0] ==
'\0')
491 xmlNs * definition(xmlSearchNs(
NULL,
reinterpret_cast<xmlNode*
>(xmlnode_),
492 reinterpret_cast<const xmlChar*
>(prefix)));
495 if (!xmlStrEqual(definition->href,
reinterpret_cast<const xmlChar*
>(name_space.
get_uri())))
496 throw xml::exception(
"Namespace definition URI differs to the given");
497 prop->ns = definition;
513 const char *name,
const ns *nspace) {
517 if ( (xmlnode ==
NULL) ||
518 (xmlnode->type != XML_ELEMENT_NODE) ||
522 const ns * ns_to_match = nspace;
523 const char * name_to_match = name;
526 const char *
column = strchr(name,
':');
535 if (*(
column + 1) ==
'\0')
539 xmlNsPtr resolved_ns = xmlSearchNs(xmlnode->doc,
541 reinterpret_cast<const xmlChar*
>(prefix.c_str()));
545 name_to_match =
column + 1;
546 ns_to_match =
new ns(
reinterpret_cast<const char *
>(resolved_ns->prefix),
547 reinterpret_cast<const char *
>(resolved_ns->href));
550 xmlAttrPtr prop = xmlnode->properties;
551 for (; prop !=
NULL; prop = prop->next) {
552 if (xmlStrEqual(prop->name,
553 reinterpret_cast<const xmlChar*
>(name_to_match))) {
554 if (ns_util::attr_ns_match(prop, ns_to_match)) {
555 if (ns_to_match != nspace)
562 if (ns_to_match != nspace)
568 const char *name,
const ns *nspace) {
569 if (xmlnode->doc != 0) {
570 xmlAttributePtr dtd_attr = 0;
571 const xmlChar* prefix = 0;
573 if (nspace && strlen(nspace->
get_prefix()) > 0)
574 prefix =
reinterpret_cast<const xmlChar*
>(nspace->
get_prefix());
576 if (xmlnode->doc->intSubset != 0) {
578 dtd_attr = xmlGetDtdQAttrDesc(xmlnode->doc->intSubset,
580 reinterpret_cast<const xmlChar*
>(name),
583 dtd_attr = xmlGetDtdAttrDesc(xmlnode->doc->intSubset,
585 reinterpret_cast<const xmlChar*
>(name));
588 if (dtd_attr == 0 && xmlnode->doc->extSubset != 0) {
590 dtd_attr = xmlGetDtdQAttrDesc(xmlnode->doc->extSubset,
592 reinterpret_cast<const xmlChar*
>(name),
595 dtd_attr = xmlGetDtdAttrDesc(xmlnode->doc->extSubset,
597 reinterpret_cast<const xmlChar*
>(name));
600 if (dtd_attr != 0 && dtd_attr->defaultValue != 0) {
608 while (current !=
NULL) {
611 current = current->
next;
620 new_phantom->
next = current;
637 return !(lhs == rhs);
647 return !(lhs == rhs);
657 return !(lhs == rhs);
const char * kInvalidDefaultIterError
This file defines the xml::ait_impl class.
This file contains the definition of the xml::attributes class.
The xml::attributes::attr class is used to hold information about one attribute.
void erase_namespace(void)
Unset the attribute's namespace.
const char * get_value(void) const
Get the value of this attribute.
void * normalize(void) const
ns set_namespace(const char *prefix)
Set the attribute's namespace.
void * get_node(void) const
void set_data(void *node, void *prop, bool def_prop)
attr & operator=(const attr &other)
bool is_default(void) const
Test if the attribute is default.
void * resolve_default_attr_ns(void) const
ns get_namespace(ns::ns_safety_type type=ns::type_safe_ns) const
Get the attribute's namespace.
void set_value(const char *value)
Set the value of this attribute.
const char * get_name(void) const
Get the name of this attribute.
Const Iterator class for accessing attribute pairs.
const_iterator & operator=(const const_iterator &other)
pointer operator->(void) const
void swap(const_iterator &other)
reference operator*(void) const
const_iterator & operator++(void)
prefix increment
Iterator class for accessing attribute pairs.
pointer operator->(void) const
iterator & operator=(const iterator &other)
void swap(iterator &other)
reference operator*(void) const
iterator & operator++(void)
prefix increment
void swap(attributes &other)
Swap this xml::attributes object with another one.
static xml::ns createUnsafeNamespace(void *libxml2RawNamespace)
static void * getUnsafeNamespacePointer(const xml::ns &name_space)
This exception class is thrown by xmlwrapp for all runtime XML-related errors along with the xml::par...
the class that does all the work behind xml::attributes::iterator and xml::attributes::const_iterator...
ait_impl & operator=(const ait_impl &other)
ait_impl & operator++(void)
attributes::attr * get(void)
ait_impl(xmlNodePtr node, xmlAttrPtr prop, bool from_find)
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.
ns_safety_type
Namespace object "safety".
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...
This file contains declarations required for iterators dereferencing support.
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static const char * column
static TDSRET convert(TDSSOCKET *tds, TDSICONV *conv, TDS_ICONV_DIRECTION direction, const char *from, size_t from_len, char *dest, size_t *dest_len)
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
void * get_ptr_to_attr_instance(void *)
phantom_attr * find_default_prop(xmlNodePtr xmlnode, const char *name, const ns *nspace)
xmlAttrPtr find_prop(xmlNodePtr xmlnode, const char *name, const ns *nspace)
node_private_data * attach_node_private_data(void *)
bool operator==(const attributes::iterator &lhs, const attributes::iterator &rhs)
bool operator!=(const attributes::iterator &lhs, const attributes::iterator &rhs)
struct phantom_attr * phantom_attrs_
xmlAttributePtr def_prop_
struct phantom_attr * next