[][src]Struct markup5ever::interface::QualName

pub struct QualName {
    pub prefix: Option<Prefix>,
    pub ns: Namespace,
    pub local: LocalName,
}

A fully qualified name (with a namespace), used to depict names of tags and attributes.

Namespaces can be used to differentiate between similar XML fragments. For example:

// HTML
<table>
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>

// Furniture XML
<table>
  <name>African Coffee Table</name>
  <width>80</width>
  <length>120</length>
</table>

Without XML namespaces, we can't use those two fragments in the same document at the same time. However if we declare a namespace we could instead say:

 
// Furniture XML
<furn:table xmlns:furn="https://furniture.rs">
  <furn:name>African Coffee Table</furn:name>
  <furn:width>80</furn:width>
  <furn:length>120</furn:length>
</furn:table>

and bind the prefix furn to a different namespace.

For this reason we parse names that contain a colon in the following way:

<furn:table>
   |    |
   |    +- local name
   |
 prefix (when resolved gives namespace_url `https://furniture.rs`)

NOTE: Prefix, LocalName and Prefix are all derivative of string_cache::atom::Atom and Atom implements Deref<str>.

Fields

prefix: Option<Prefix>

The prefix of qualified (e.g. furn in <furn:table> above). Optional (since some namespaces can be empty or inferred), and only useful for namespace resolution (since different prefix can still resolve to same namespace)


use markup5ever::{QualName, Namespace, LocalName, Prefix};
 
let qual = QualName::new(
    Some(Prefix::from("furn")),
    Namespace::from("https://furniture.rs"),
    LocalName::from("table"),
);
 
assert_eq!("furn", &qual.prefix.unwrap());
 
ns: Namespace

The namespace after resolution (e.g. https://furniture.rs in example above).

 
 
assert_eq!("https://furniture.rs", &qual.ns);

When matching namespaces used by HTML we can use ns! macro. Although keep in mind that ns! macro only works with namespaces that are present in HTML spec (like html, xmlns, svg, etc.).

#[macro_use] extern crate markup5ever;
 
 
let html_table = QualName::new(
   None,
   ns!(html),
   LocalName::from("table"),
);
 
assert!(
  match html_table.ns {
    ns!(html) => true,
    _ => false,
  }
);
 
local: LocalName

The local name (e.g. table in <furn:table> above).

 
 
assert_eq!("table", &qual.local);

When matching local name we can also use the local_name! macro:

#[macro_use] extern crate markup5ever;
 
 
 
// Initialize qual to furniture example 
 
assert!(
  match qual.local {
    local_name!("table") => true,
    _ => false,
  }
);
 

Methods

impl QualName[src]

pub fn new(prefix: Option<Prefix>, ns: Namespace, local: LocalName) -> QualName[src]

Basic constructor function.

First let's try it for the following example where QualName is defined as:

<furn:table> <!-- namespace url is https://furniture.rs -->

Given this definition, we can define QualName using strings.

use markup5ever::{QualName, Namespace, LocalName, Prefix};
 
let qual_name = QualName::new(
    Some(Prefix::from("furn")),
    Namespace::from("https://furniture.rs"),
    LocalName::from("table"),
);

If we were instead to construct this element instead:

 
<table>
 ^^^^^---- no prefix and thus default html namespace
 

Or could define it using macros, like so:

#[macro_use] extern crate markup5ever;
use markup5ever::{QualName, Namespace, LocalName, Prefix};
 
let qual_name = QualName::new(
    None,
    ns!(html),
    local_name!("table")
);

Let's analyse the above example. Since we have no prefix its value is None. Second we have html namespace. In html5ever html namespaces are supported out of the box, we can write ns!(html) instead of typing Namespace::from("http://www.w3.org/1999/xhtml"). Local name is also one of the HTML elements local names, so can use local_name!("table") macro.

pub fn expanded(&self) -> ExpandedName[src]

Take a reference of self as an ExpandedName, dropping the unresolved prefix.

In XML and HTML prefixes are only used to extract the relevant namespace URI. Expanded name only contains resolved namespace and tag name, which are only relevant parts of an XML or HTML tag and attribute name respectively.

In lieu of our XML Namespace example

<furn:table> <!-- namespace url is https://furniture.rs -->

For it the expanded name would become roughly equivalent to:

ExpandedName {
   ns: "https://furniture.rs",
   local: "table",
}

Trait Implementations

impl PartialEq<QualName> for QualName[src]

impl Clone for QualName[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Ord for QualName[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl Eq for QualName[src]

impl PartialOrd<QualName> for QualName[src]

impl Debug for QualName[src]

impl Hash for QualName[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl Send for QualName

impl Sync for QualName

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]