class Openwsman::XmlNode
XmlNode
is a node inside the XML document tree.
A node has
-
a name
-
a namespace (optional)
-
attributes
-
text (optional)
-
a parent
-
a document (root)
-
children (empty for tail nodes)
Public Instance Methods
add(p1)
click to toggle source
add child (namespace, name, text) to node
WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
attr_add("namespace", "name", "value") → XmlAttr
click to toggle source
add attribute to node
WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
attr_count → Integer
click to toggle source
count node attribute
int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
attr_find("namespace", "name") → XmlAttr
click to toggle source
find node attribute by name
WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
child → XmlNode
click to toggle source
get first child of node
WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
doc → XmlDoc
click to toggle source
get XmlDoc to which node belongs
WsXmlDocH doc() { return ws_xml_get_node_doc( $self ); } /* * get parent for node * * call-seq: * node.parent -> XmlNode * */ WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } %alias child "first"; /* * get first child of node * * call-seq: * node.child -> XmlNode * */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
dump_file(IO) → nil
click to toggle source
dump node to file
void dump_file(FILE *fp) { ws_xml_dump_node_tree( fp, $self ); } %alias equal "=="; %typemap(out) int equal "$result = ($1 != 0) ? Qtrue : Qfalse;"; int equal( WsXmlNodeH n ) /* * Test for identity (same object) * * call-seq: * XmlNode == XmlNode -> Boolean * */ { return $self == n; } /* * get text (without xml tags) of node * * alias: to_s * * call-seq: * node.text() -> String * */ char *text() { return ws_xml_get_node_text( $self ); } %rename( "text=" ) set_text( const char *text ); /* * Set text of node * * call-seq: * node.text = String * */ void set_text( const char *text ) { ws_xml_set_node_text( $self, text ); } /* * get XmlDoc to which node belongs * * call-seq: * node.doc -> XmlDoc * */ WsXmlDocH doc() { return ws_xml_get_node_doc( $self ); } /* * get parent for node * * call-seq: * node.parent -> XmlNode * */ WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } %alias child "first"; /* * get first child of node * * call-seq: * node.child -> XmlNode * */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
each_attr { |XmlAttr| ... }
click to toggle source
enumerate attributes
void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
epr("namespace", "epr_node_name", Integer embedded) → EndPointReference
click to toggle source
get end point reference
epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
lang = String
click to toggle source
set language
void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
name → String
click to toggle source
get name for node
char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
name = String
click to toggle source
set name of node
void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
ns → String
click to toggle source
get namespace for node
char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
ns = String
click to toggle source
set namespace of node
void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
parent → XmlNode
click to toggle source
get parent for node
WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } %alias child "first"; /* * get first child of node * * call-seq: * node.child -> XmlNode * */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
prefix → String
click to toggle source
get prefix of nodes namespace
const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
string(XmlNode) → String
click to toggle source
dump node as XML string
alias: to_xml
char *string() { int size; char *buf; ws_xml_dump_memory_node_tree( $self, &buf, &size ); return buf; } /* * dump node to file * * call-seq: * node.dump_file(IO) -> nil * */ void dump_file(FILE *fp) { ws_xml_dump_node_tree( fp, $self ); } %alias equal "=="; %typemap(out) int equal "$result = ($1 != 0) ? Qtrue : Qfalse;"; int equal( WsXmlNodeH n ) /* * Test for identity (same object) * * call-seq: * XmlNode == XmlNode -> Boolean * */ { return $self == n; } /* * get text (without xml tags) of node * * alias: to_s * * call-seq: * node.text() -> String * */ char *text() { return ws_xml_get_node_text( $self ); } %rename( "text=" ) set_text( const char *text ); /* * Set text of node * * call-seq: * node.text = String * */ void set_text( const char *text ) { ws_xml_set_node_text( $self, text ); } /* * get XmlDoc to which node belongs * * call-seq: * node.doc -> XmlDoc * */ WsXmlDocH doc() { return ws_xml_get_node_doc( $self ); } /* * get parent for node * * call-seq: * node.parent -> XmlNode * */ WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } %alias child "first"; /* * get first child of node * * call-seq: * node.child -> XmlNode * */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
text() → String
click to toggle source
get text (without xml tags) of node
alias: to_s
char *text() { return ws_xml_get_node_text( $self ); } %rename( "text=" ) set_text( const char *text ); /* * Set text of node * * call-seq: * node.text = String * */ void set_text( const char *text ) { ws_xml_set_node_text( $self, text ); } /* * get XmlDoc to which node belongs * * call-seq: * node.doc -> XmlDoc * */ WsXmlDocH doc() { return ws_xml_get_node_doc( $self ); } /* * get parent for node * * call-seq: * node.parent -> XmlNode * */ WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } %alias child "first"; /* * get first child of node * * call-seq: * node.child -> XmlNode * */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }
text = String
click to toggle source
Set text of node
void set_text( const char *text ) { ws_xml_set_node_text( $self, text ); } /* * get XmlDoc to which node belongs * * call-seq: * node.doc -> XmlDoc * */ WsXmlDocH doc() { return ws_xml_get_node_doc( $self ); } /* * get parent for node * * call-seq: * node.parent -> XmlNode * */ WsXmlNodeH parent() { return ws_xml_get_node_parent( $self ); } %alias child "first"; /* * get first child of node * * call-seq: * node.child -> XmlNode * */ WsXmlNodeH child() { return xml_parser_get_first_child($self); } /* * get name for node * * call-seq: * node.name -> String * */ char *name() { return ws_xml_get_node_local_name( $self ); } %rename("name=") set_name( const char *name); /* * set name of node * * call-seq: * node.name = String * */ void set_name( const char *name ) { ws_xml_set_node_name( $self, ws_xml_get_node_name_ns( $self ), name ); } /* * get namespace for node * * call-seq: * node.ns -> String * */ char *ns() { return ws_xml_get_node_name_ns( $self ); } %rename("ns=") set_ns( const char *nsuri ); /* * set namespace of node * * call-seq: * node.ns = String * */ void set_ns( const char *ns ) { ws_xml_set_ns( $self, ns, ws_xml_get_node_name_ns_prefix($self) ); } /* * get prefix of nodes namespace * * call-seq: * node.prefix -> String * */ const char *prefix() { return ws_xml_get_node_name_ns_prefix($self); } %rename("lang=") set_lang(const char *lang); /* * set language * * call-seq: * node.lang = String * */ void set_lang(const char *lang) { ws_xml_set_node_lang($self, lang); } /* * find node within tree * a NULL passed as 'ns' (namespace) is treated as wildcard * * call-seq: * node.find("namespace", "name") -> XmlNode # recursive * node.find("namespace", "name", 0) -> XmlNode # non-recursive * */ WsXmlNodeH find( const char *ns, const char *name, int recursive = 1) { return ws_xml_find_in_tree( $self, ns, name, recursive ); } /* * iterate over siblings * * finds next sibling with same namespace and name * * See also XmlNode#each * * XmlNode#each iterates over children, XmlNode#next over siblings * * Example: * <Foo> * <Bar>... * <Bar>... * <Bar>... * <Bar>... * <Other>... * <Other>... * </Foo> * * node = root.Foo # points to <Foo> node * * bar = node.Bar * while bar do * bar = bar.next * end * * will give you four iterations (all <Bar> nodes) * * child = node.Bar * while child do * child = child.next(1) * end * * will give you six iterations (all children of <Foo>) * The latter example is equal to * * node.each do |child| * ... * end * */ WsXmlNodeH next(int all = 0) { WsXmlNodeH next_node = xml_parser_get_next_child($self); if (next_node && !all) { const char *ns_uri = ws_xml_get_node_name_ns($self); const char *name = ws_xml_get_node_local_name($self); if (ws_xml_is_node_qname(next_node, ns_uri, name) == 0) { next_node = NULL; } } return next_node; } /* * count node children * if name given, count children with this name * if name + ns given, count children with this namespace and name * */ int size(const char *name = NULL, const char *ns = NULL) { return ws_xml_get_child_count_by_qname($self, ns, name); } /* * add child (namespace, name, text) to node * */ WsXmlNodeH add( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_child( $self, ns, name, text ); } /* * add child (namespace, name, text) before(!) node * */ WsXmlNodeH add_before( const char *ns, const char *name, const char *text = NULL ) { return ws_xml_add_prev_sibling( $self, ns, name, text ); } %alias add "<<"; /* * add node as child * */ WsXmlNodeH add(WsXmlNodeH node) { ws_xml_duplicate_tree( $self, node ); return $self; } /* * iterate over children * * See also XmlNode#next * * XmlNode#each iterates over children, XmlNode#next over siblings * * can be limited to children with specific name (and specific namespace) * * for array-like constructs, e.g * <Parent> * <Child>.. * <Child>.. * <Child>.. * <OtherChild>.. * <OtherChild>.. * <OtherChild>.. * * doc.Parent.each do |child| * ... iterates over all 6 children ... * end * * use XmlNode#next as in * node = doc.OtherChild * while node do * ... do something with node ... * node = node.next * end * * call-seq: * node.each { |XmlNode| ... } * node.each("name") { |XmlNode| ... } * node.each("name", "namespace") { |XmlNode| ... } * */ void each(const char *name = NULL, const char *ns = NULL) { int i = 0; WsXmlNodeH node = $self; int count = ws_xml_get_child_count_by_qname( node, ns, name ); while ( i < count ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_child(node, i, ns, name), SWIGTYPE_p___WsXmlNode, 0)); ++i; } } %alias get "[]"; /* * get child by index * * call-seq: * node.get(42) -> XmlNode * node.get(42, "name") -> XmlNode * node.get(42, "name", "namespace") -> XmlNode * */ WsXmlNodeH get(int i, const char *name = NULL, const char *ns = NULL) { if (i < 0 || i >= ws_xml_get_child_count_by_qname($self,ns,name)) return NULL; return ws_xml_get_child($self, i, ns, name); } /* * get first child by name (and namespace) * * call-seq: * node.get("name") -> XmlNode * node.get("name", "namespace") -> XmlNode * */ WsXmlNodeH get(const char *name, const char *ns = NULL) { return ws_xml_get_child($self, 0, ns, name); } /* * get node attribute by index or name * * call-seq: * node.attr(1) -> XmlAttr * node.attr("name") -> XmlAttr * node.attr("name", "namespace") -> XmlAttr * */ WsXmlAttrH attr(VALUE index = Qnil, VALUE namespace = Qnil) { if (NIL_P(index)) { /* nil */ return ws_xml_get_node_attr( $self, 0 ); } else if (FIXNUM_P(index)) { /* numeric */ return ws_xml_get_node_attr( $self, FIX2INT(index) ); } else { /* convert to string */ const char *ns = NULL; const char *name = as_string(index); if (!NIL_P(namespace)) { ns = as_string(namespace); } return ws_xml_find_node_attr( $self, ns, name ); } } /* * count node attribute * * call-seq: * node.attr_count -> Integer * */ int attr_count() { return ws_xml_get_node_attr_count( $self ); } /* * find node attribute by name * * call-seq: * node.attr_find("namespace", "name") -> XmlAttr * */ WsXmlAttrH attr_find( const char *ns, const char *name ) { return ws_xml_find_node_attr( $self, ns, name ); } /* * add attribute to node * * call-seq: * node.attr_add("namespace", "name", "value") -> XmlAttr * */ WsXmlAttrH attr_add( const char *ns, const char *name, const char *value ) { return ws_xml_add_node_attr( $self, ns, name, value ); } /* * get end point reference * * call-seq: * node.epr("namespace", "epr_node_name", Integer embedded) -> EndPointReference * */ epr_t *epr( const char *ns, const char *epr_node_name, int embedded) { return epr_deserialize($self, ns, epr_node_name, embedded); } /* * enumerate attributes * * call-seq: * node.each_attr { |XmlAttr| ... } * */ void each_attr() { int i = 0; while ( i < ws_xml_get_node_attr_count( $self ) ) { rb_yield( SWIG_NewPointerObj((void*) ws_xml_get_node_attr($self, i), SWIGTYPE_p___WsXmlAttr, 0)); ++i; } } }