pub struct Document { /* private fields */ }Expand description
A parsed XML document.
Implementations§
Source§impl Document
impl Document
Sourcepub fn query_text(
&self,
expression: &str,
namespaces: Option<Vec<String>>,
) -> Result<Vec<String>, JsError>
pub fn query_text( &self, expression: &str, namespaces: Option<Vec<String>>, ) -> Result<Vec<String>, JsError>
Evaluate an XPath expression and return the matched nodes’
text, as an array of strings.
Returning text rather than node handles is deliberate: a
NodeId is only meaningful against the document that issued
it, and handing an opaque integer across the WASM boundary
invites exactly the misuse the Rust API’s lifetime rules
prevent.
namespaces binds prefixes for the expression, each written
"PREFIX=URI" — the same spelling oxml-cli takes for --ns.
A prefix resolves against these bindings and not against the
document, so one query works across documents that spell the
prefix differently. An unbound prefix is an error.
§Errors
Returns a JsError if the expression is malformed or uses an
unbound prefix.
Sourcepub fn query_value(
&self,
expression: &str,
namespaces: Option<Vec<String>>,
) -> Result<String, JsError>
pub fn query_value( &self, expression: &str, namespaces: Option<Vec<String>>, ) -> Result<String, JsError>
Evaluate an XPath expression and return its value as a string.
Use this for expressions that are not node-sets — count(..),
string(..), a comparison.
namespaces binds prefixes for the expression, each written
"PREFIX=URI" — the same spelling oxml-cli takes for --ns.
A prefix resolves against these bindings and not against the
document, so one query works across documents that spell the
prefix differently. An unbound prefix is an error.
§Errors
Returns a JsError if the expression is malformed or uses an
unbound prefix.
Sourcepub fn query_count(
&self,
expression: &str,
namespaces: Option<Vec<String>>,
) -> Result<usize, JsError>
pub fn query_count( &self, expression: &str, namespaces: Option<Vec<String>>, ) -> Result<usize, JsError>
How many nodes an expression matches.
namespaces binds prefixes for the expression, each written
"PREFIX=URI" — the same spelling oxml-cli takes for --ns.
A prefix resolves against these bindings and not against the
document, so one query works across documents that spell the
prefix differently. An unbound prefix is an error.
§Errors
Returns a JsError if the expression is malformed or uses an
unbound prefix.
Sourcepub fn to_xml(&self) -> String
pub fn to_xml(&self) -> String
The document as XML.
The counterpart to parse. Reading a document and writing it
back previously meant reaching for XMLSerializer and holding
two representations of the same thing.
Round-trips: the output parses to a document that serialises identically. It is not guaranteed byte-identical to the input, because a document has more than one valid spelling – entity references and attribute order among them.
Trait Implementations§
Source§impl FromWasmAbi for Document
impl FromWasmAbi for Document
Source§impl IntoWasmAbi for Document
impl IntoWasmAbi for Document
Source§impl LongRefFromWasmAbi for Document
impl LongRefFromWasmAbi for Document
Source§impl OptionFromWasmAbi for Document
impl OptionFromWasmAbi for Document
Source§impl OptionIntoWasmAbi for Document
impl OptionIntoWasmAbi for Document
Source§impl RefFromWasmAbi for Document
impl RefFromWasmAbi for Document
Source§type Abi = WasmPtr<WasmRefCell<Document>>
type Abi = WasmPtr<WasmRefCell<Document>>
Self are recovered from.Source§impl RefMutFromWasmAbi for Document
impl RefMutFromWasmAbi for Document
impl SupportsConstructor for Document
impl SupportsInstanceProperty for Document
impl SupportsStaticProperty for Document
Source§impl TryFromJsValue for Document
impl TryFromJsValue for Document
Source§impl VectorFromWasmAbi for Document
impl VectorFromWasmAbi for Document
Source§impl VectorIntoWasmAbi for Document
impl VectorIntoWasmAbi for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.