use std::io; use std::io::prelude::*; use std::fmt; use std::result; use std::borrow::Cow; use std::error::Error;
use common; use name::{Name, OwnedName}; use attribute::Attribute; use escape::{escape_str_attribute, escape_str_pcdata}; use common::XmlVersion; use namespace::{NamespaceStack, NS_NO_PREFIX, NS_EMPTY_URI, NS_XMLNS_PREFIX, NS_XML_PREFIX};
use writer::config::EmitterConfig;
/// An error which may be returned by `XmlWriter` when writing XML events. #[derive(Debug)] pubenum EmitterError { /// An I/O error occured in the underlying `Write` instance.
Io(io::Error),
/// Document declaration has already been written to the output stream.
DocumentStartAlreadyEmitted,
/// The name of the last opening element is not available.
LastElementNameNotAvailable,
/// The name of the last opening element is not equal to the name of the provided /// closing element.
EndElementNameIsNotEqualToLastStartElementName,
/// End element name is not specified when it is needed, for example, when automatic /// closing is not enabled in configuration.
EndElementNameIsNotSpecified
}
impl Error for EmitterError { fn description(&self) -> &str { match *self {
EmitterError::Io(_) => "I/O error",
EmitterError::DocumentStartAlreadyEmitted => "document start event has already been emitted",
EmitterError::LastElementNameNotAvailable => "last element name is not available",
EmitterError::EndElementNameIsNotEqualToLastStartElementName => "end element name is not equal to last start element name",
EmitterError::EndElementNameIsNotSpecified => "end element name is not specified and can't be inferred",
}
}
}
/// A result type yielded by `XmlWriter`. pubtype Result<T> = result::Result<T, EmitterError>;
// TODO: split into a low-level fast writer without any checks and formatting logic and a // high-level indenting validating writer pubstruct Emitter {
config: EmitterConfig,
if !self.config.normalize_empty_elements {
write!(target, ">")?;
}
Ok(())
}
pubfn emit_current_namespace_attributes<W>(&mutself, target: &an style='color:red'>mut W) -> Result<()> where W: Write
{ for (prefix, uri) inself.nst.peek() { match prefix { // internal namespaces are not emitted
NS_XMLNS_PREFIX | NS_XML_PREFIX => Ok(()), //// there is already a namespace binding with this prefix in scope //prefix if self.nst.get(prefix) == Some(uri) => Ok(()), // emit xmlns only if it is overridden
NS_NO_PREFIX => if uri != NS_EMPTY_URI {
write!(target, " xmlns=\"{}\"", uri)
} else { Ok(()) }, // everything else
prefix => write!(target, " xmlns:{}=\"{}\"", prefix, uri)
}?;
}
Ok(())
}
// Check that last started element name equals to the provided name, if there are both iflet Some(ref last_name) = owned_name { iflet Some(ref name) = name { if last_name.borrow() != *name { return Err(EmitterError::EndElementNameIsNotEqualToLastStartElementName);
}
}
}
iflet Some(name) = owned_name.as_ref().map(|n| n.borrow()).or(name) { ifself.config.normalize_empty_elements && self.just_wrote_start_element { self.just_wrote_start_element = false; let termination = ifself.config.pad_self_closing { " />" } else { "/>" }; let result = target.write_all(termination.as_bytes()).map_err(From::from); self.after_end_element();
result
} else { self.just_wrote_start_element = false;
self.before_end_element(target)?; let result = write!(target, "</{}>", name.repr_display()).map_err(From::from); self.after_end_element();
result
}
} else {
Err(EmitterError::EndElementNameIsNotSpecified)
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.