@@ -481,12 +481,35 @@ impl Node {
481481 }
482482 }
483483
484+ /// Return an attribute in a namespace `ns` as a `Node` of type AttributeNode
485+ pub fn get_property_node_ns ( & self , name : & str , ns : & str ) -> Option < Node > {
486+ let c_name = CString :: new ( name) . unwrap ( ) ;
487+ let c_ns = CString :: new ( ns) . unwrap ( ) ;
488+ let attr_node = unsafe {
489+ xmlHasNsProp (
490+ self . node_ptr ( ) ,
491+ c_name. as_bytes ( ) . as_ptr ( ) ,
492+ c_ns. as_bytes ( ) . as_ptr ( ) ,
493+ )
494+ } ;
495+ self . ptr_as_option ( attr_node as xmlNodePtr )
496+ }
497+
498+ /// Return an attribute with no namespace as a `Node` of type AttributeNode
499+ pub fn get_property_node_no_ns ( & self , name : & str ) -> Option < Node > {
500+ let c_name = CString :: new ( name) . unwrap ( ) ;
501+ let attr_node =
502+ unsafe { xmlHasNsProp ( self . node_ptr ( ) , c_name. as_bytes ( ) . as_ptr ( ) , ptr:: null ( ) ) } ;
503+ self . ptr_as_option ( attr_node as xmlNodePtr )
504+ }
505+
484506 /// Check if a property has been defined, without allocating its value
485507 pub fn has_property ( & self , name : & str ) -> bool {
486508 let c_name = CString :: new ( name) . unwrap ( ) ;
487509 let value_ptr = unsafe { xmlHasProp ( self . node_ptr ( ) , c_name. as_bytes ( ) . as_ptr ( ) ) } ;
488510 !value_ptr. is_null ( )
489511 }
512+
490513 /// Check if property `name` in namespace `ns` exists
491514 pub fn has_property_ns ( & self , name : & str , ns : & str ) -> bool {
492515 let c_name = CString :: new ( name) . unwrap ( ) ;
@@ -500,6 +523,15 @@ impl Node {
500523 } ;
501524 !value_ptr. is_null ( )
502525 }
526+
527+ /// Check if property `name` with no namespace exists
528+ pub fn has_property_no_ns ( & self , name : & str ) -> bool {
529+ let c_name = CString :: new ( name) . unwrap ( ) ;
530+ let value_ptr =
531+ unsafe { xmlHasNsProp ( self . node_ptr ( ) , c_name. as_bytes ( ) . as_ptr ( ) , ptr:: null ( ) ) } ;
532+ !value_ptr. is_null ( )
533+ }
534+
503535 /// Alias for has_property
504536 pub fn has_attribute ( & self , name : & str ) -> bool {
505537 self . has_property ( name)
@@ -509,6 +541,11 @@ impl Node {
509541 self . has_property_ns ( name, ns)
510542 }
511543
544+ /// Alias for has_property_no_ns
545+ pub fn has_attribute_no_ns ( & self , name : & str ) -> bool {
546+ self . has_property_no_ns ( name)
547+ }
548+
512549 /// Sets the value of property `name` to `value`
513550 pub fn set_property (
514551 & mut self ,
@@ -601,6 +638,33 @@ impl Node {
601638 }
602639 }
603640
641+ /// Removes the property of given `name` with no namespace
642+ pub fn remove_property_no_ns ( & mut self , name : & str ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
643+ let c_name = CString :: new ( name) . unwrap ( ) ;
644+ let attr_node = unsafe {
645+ xmlHasNsProp (
646+ self . node_ptr_mut ( ) ?,
647+ c_name. as_bytes ( ) . as_ptr ( ) ,
648+ ptr:: null ( ) ,
649+ )
650+ } ;
651+ if !attr_node. is_null ( ) {
652+ let remove_prop_status = unsafe { xmlRemoveProp ( attr_node) } ;
653+ if remove_prop_status == 0 {
654+ Ok ( ( ) )
655+ } else {
656+ // Propagate libxml2 failure to remove
657+ Err ( From :: from ( format ! (
658+ "libxml2 failed to remove property with status: {:?}" ,
659+ remove_prop_status
660+ ) ) )
661+ }
662+ } else {
663+ // silently no-op if asked to remove a property which is not present
664+ Ok ( ( ) )
665+ }
666+ }
667+
604668 /// Alias for get_property
605669 pub fn get_attribute ( & self , name : & str ) -> Option < String > {
606670 self . get_property ( name)
@@ -621,6 +685,16 @@ impl Node {
621685 self . get_property_node ( name)
622686 }
623687
688+ /// Alias for get_property_node_ns
689+ pub fn get_attribute_node_ns ( & self , name : & str , ns : & str ) -> Option < Node > {
690+ self . get_property_node_ns ( name, ns)
691+ }
692+
693+ /// Alias for get_property_node_no_ns
694+ pub fn get_attribute_node_no_ns ( & self , name : & str ) -> Option < Node > {
695+ self . get_property_node_no_ns ( name)
696+ }
697+
624698 /// Alias for set_property
625699 pub fn set_attribute (
626700 & mut self ,
@@ -653,6 +727,11 @@ impl Node {
653727 self . remove_property_ns ( name, ns)
654728 }
655729
730+ /// Alias for remove_property_no_ns
731+ pub fn remove_attribute_no_ns ( & mut self , name : & str ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
732+ self . remove_property_no_ns ( name)
733+ }
734+
656735 /// Get a copy of the attributes of this node
657736 pub fn get_properties ( & self ) -> HashMap < String , String > {
658737 let mut attributes = HashMap :: new ( ) ;
0 commit comments