Merge branch 'element_has_ns' into 'master'

add Element::has_ns(&self, NS)

See merge request !16
This commit is contained in:
lumi 2017-08-20 15:03:14 +00:00
commit 87a19e5e58

View file

@ -263,7 +263,23 @@ impl Element {
/// ``` /// ```
pub fn is<N: AsRef<str>, NS: AsRef<str>>(&self, name: N, namespace: NS) -> bool { pub fn is<N: AsRef<str>, NS: AsRef<str>>(&self, name: N, namespace: NS) -> bool {
self.name == name.as_ref() && self.name == name.as_ref() &&
self.namespaces.has(&self.prefix, namespace) self.has_ns(namespace)
}
/// Returns whether the element has the given namespace.
///
/// # Examples
///
/// ```rust
/// use minidom::Element;
///
/// let elem = Element::builder("name").ns("namespace").build();
///
/// assert_eq!(elem.has_ns("namespace"), true);
/// assert_eq!(elem.has_ns("wrong"), false);
/// ```
pub fn has_ns<NS: AsRef<str>>(&self, namespace: NS) -> bool {
self.namespaces.has(&self.prefix, namespace)
} }
/// Parse a document from an `EventReader`. /// Parse a document from an `EventReader`.