[][src]Struct xml::name::Name

pub struct Name<'a> {
    pub local_name: &'a str,
    pub namespace: Option<&'a str>,
    pub prefix: Option<&'a str>,
}

Represents a qualified XML name.

A qualified name always consists at least of a local name. It can optionally contain a prefix; when reading an XML document, if it contains a prefix, it must also contain a namespace URI, but this is not enforced statically; see below. The name can contain a namespace without a prefix; in that case a default, empty prefix is assumed.

When writing XML documents, it is possible to omit the namespace URI, leaving only the prefix. In this case the writer will check that the specifed prefix is bound to some URI in the current namespace context. If both prefix and namespace URI are specified, it is checked that the current namespace context contains this exact correspondence between prefix and namespace URI.

Prefixes and URIs

A qualified name with a prefix must always contain a proper namespace URI --- names with a prefix but without a namespace associated with that prefix are meaningless. However, it is impossible to obtain proper namespace URI by a prefix without a context, and such context is only available when parsing a document (or it can be constructed manually when writing a document). Tying a name to a context statically seems impractical. This may change in future, though.

Conversions

Name implements some From instances for conversion from strings and tuples. For example:

let n1: Name = "p:some-name".into();
let n2: Name = ("p", "some-name").into();

assert_eq!(n1, n2);
assert_eq!(n1.local_name, "some-name");
assert_eq!(n1.prefix, Some("p"));
assert!(n1.namespace.is_none());

This is added to support easy specification of XML elements when writing XML documents.

Fields

local_name: &'a str

A local name, e.g. string in xsi:string.

namespace: Option<&'a str>

A namespace URI, e.g. http://www.w3.org/2000/xmlns/.

prefix: Option<&'a str>

A name prefix, e.g. xsi in xsi:string.

Methods

impl<'a> Name<'a>[src]

pub fn to_owned(&self) -> OwnedName[src]

Returns an owned variant of the qualified name.

pub fn local(local_name: &str) -> Name[src]

Returns a new Name instance representing plain local name.

pub fn prefixed(local_name: &'a str, prefix: &'a str) -> Name<'a>[src]

Returns a new Name instance with the given local name and prefix.

pub fn qualified(
    local_name: &'a str,
    namespace: &'a str,
    prefix: Option<&'a str>
) -> Name<'a>
[src]

Returns a new Name instance representing a qualified name with or without a prefix and with a namespace URI.

pub fn to_repr(&self) -> String[src]

Returns a correct XML representation of this local name and prefix.

This method is different from the autoimplemented to_string() because it does not include namespace URI in the result.

pub fn repr_display(&self) -> ReprDisplay[src]

Returns a structure which can be displayed with std::fmt machinery to obtain this local name and prefix.

This method is needed for efficiency purposes in order not to create unnecessary allocations.

pub fn prefix_repr(&self) -> &str[src]

Returns either a prefix of this name or namespace::NS_NO_PREFIX constant.

Trait Implementations

impl<'a> Clone for Name<'a>[src]

impl<'a> Copy for Name<'a>[src]

impl<'a> Debug for Name<'a>[src]

impl<'a> Display for Name<'a>[src]

impl<'a> Eq for Name<'a>[src]

impl<'a> From<&'a str> for Name<'a>[src]

impl<'a> From<(&'a str, &'a str)> for Name<'a>[src]

impl<'a> From<Name<'a>> for OwnedName[src]

impl<'a> Hash for Name<'a>[src]

impl<'a> PartialEq<Name<'a>> for Name<'a>[src]

impl<'a> StructuralEq for Name<'a>[src]

impl<'a> StructuralPartialEq for Name<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Name<'a>

impl<'a> Send for Name<'a>

impl<'a> Sync for Name<'a>

impl<'a> Unpin for Name<'a>

impl<'a> UnwindSafe for Name<'a>

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.