minidom: breaking: Allow getting Element attributes by namespace
- Move Element.attributes to `AttrMap`, slowly using rxml's features and unrolling our own. - Add Element::attr_ns that requires the attribute namespace. Element:attr defaults to rxml::Namespace::none() but the interface changes nonetheless for a &NcNameStr. Similar changes on `ElementBuilder` methods. - Remove iterator structs for attributes, return a ref on the AttrMap directly as we don't need to keep attributes' internals hidden anymore. - Enable rxml's `macros` feature within tests to access the `xml_ncname` macro. Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
48f67d034e
commit
19865e5f1e
14 changed files with 272 additions and 236 deletions
|
|
@ -1126,19 +1126,35 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn minidom() {
|
fn minidom() {
|
||||||
let elem: minidom::Element = "<message xmlns='ns1' from='a@b/c'/>".parse().unwrap();
|
let elem: minidom::Element = "<message xmlns='ns1' from='a@b/c'/>".parse().unwrap();
|
||||||
let to: Jid = elem.attr("from").unwrap().parse().unwrap();
|
let to: Jid = elem
|
||||||
|
.attr("from".try_into().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.parse()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(to, Jid::from(FullJid::new("a@b/c").unwrap()));
|
assert_eq!(to, Jid::from(FullJid::new("a@b/c").unwrap()));
|
||||||
|
|
||||||
let elem: minidom::Element = "<message xmlns='ns1' from='a@b'/>".parse().unwrap();
|
let elem: minidom::Element = "<message xmlns='ns1' from='a@b'/>".parse().unwrap();
|
||||||
let to: Jid = elem.attr("from").unwrap().parse().unwrap();
|
let to: Jid = elem
|
||||||
|
.attr("from".try_into().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.parse()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(to, Jid::from(BareJid::new("a@b").unwrap()));
|
assert_eq!(to, Jid::from(BareJid::new("a@b").unwrap()));
|
||||||
|
|
||||||
let elem: minidom::Element = "<message xmlns='ns1' from='a@b/c'/>".parse().unwrap();
|
let elem: minidom::Element = "<message xmlns='ns1' from='a@b/c'/>".parse().unwrap();
|
||||||
let to: FullJid = elem.attr("from").unwrap().parse().unwrap();
|
let to: FullJid = elem
|
||||||
|
.attr("from".try_into().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.parse()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(to, FullJid::new("a@b/c").unwrap());
|
assert_eq!(to, FullJid::new("a@b/c").unwrap());
|
||||||
|
|
||||||
let elem: minidom::Element = "<message xmlns='ns1' from='a@b'/>".parse().unwrap();
|
let elem: minidom::Element = "<message xmlns='ns1' from='a@b'/>".parse().unwrap();
|
||||||
let to: BareJid = elem.attr("from").unwrap().parse().unwrap();
|
let to: BareJid = elem
|
||||||
|
.attr("from".try_into().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.parse()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(to, BareJid::new("a@b").unwrap());
|
assert_eq!(to, BareJid::new("a@b").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1147,21 +1163,30 @@ mod tests {
|
||||||
fn minidom_into_attr() {
|
fn minidom_into_attr() {
|
||||||
let full = FullJid::new("a@b/c").unwrap();
|
let full = FullJid::new("a@b/c").unwrap();
|
||||||
let elem = minidom::Element::builder("message", "jabber:client")
|
let elem = minidom::Element::builder("message", "jabber:client")
|
||||||
.attr("from", full.clone())
|
.attr("from".try_into().unwrap(), full.clone())
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(elem.attr("from"), Some(full.to_string().as_str()));
|
assert_eq!(
|
||||||
|
elem.attr("from".try_into().unwrap()),
|
||||||
|
Some(full.to_string().as_str())
|
||||||
|
);
|
||||||
|
|
||||||
let bare = BareJid::new("a@b").unwrap();
|
let bare = BareJid::new("a@b").unwrap();
|
||||||
let elem = minidom::Element::builder("message", "jabber:client")
|
let elem = minidom::Element::builder("message", "jabber:client")
|
||||||
.attr("from", bare.clone())
|
.attr("from".try_into().unwrap(), bare.clone())
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(elem.attr("from"), Some(bare.to_string().as_str()));
|
assert_eq!(
|
||||||
|
elem.attr("from".try_into().unwrap()),
|
||||||
|
Some(bare.to_string().as_str())
|
||||||
|
);
|
||||||
|
|
||||||
let jid = Jid::from(bare.clone());
|
let jid = Jid::from(bare.clone());
|
||||||
let _elem = minidom::Element::builder("message", "jabber:client")
|
let _elem = minidom::Element::builder("message", "jabber:client")
|
||||||
.attr("from", jid)
|
.attr("from".try_into().unwrap(), jid)
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(elem.attr("from"), Some(bare.to_string().as_str()));
|
assert_eq!(
|
||||||
|
elem.attr("from".try_into().unwrap()),
|
||||||
|
Some(bare.to_string().as_str())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,12 @@ Version NEXT:
|
||||||
* Breaking:
|
* Breaking:
|
||||||
* Removed 'std' feature for now because it makes build fail on
|
* Removed 'std' feature for now because it makes build fail on
|
||||||
no-default-features.
|
no-default-features.
|
||||||
|
* Add `Element::attr_ns` that requires the attribute namespace in addition
|
||||||
|
to `Element::attr` (which defaults to `rxml::Namespace::none()`. Similar
|
||||||
|
changes on `ElementBuilder` methods.
|
||||||
|
`Element` now uses `AttrMap` to store attributes, and this also implies
|
||||||
|
some more changes in the Element interface such as iterators on
|
||||||
|
attributes.
|
||||||
* Changes
|
* Changes
|
||||||
* Use thiserror for the error type. (!616)
|
* Use thiserror for the error type. (!616)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,6 @@ gitlab = { repository = "xmpp-rs/xmpp-rs" }
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rxml = { version = "0.13.1", default-features = false, features = [ "std", "compact_str" ] }
|
rxml = { version = "0.13.1", default-features = false, features = [ "std", "compact_str" ] }
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
rxml = { version = "0.13.1", default-features = false, features = [ "std", "compact_str", "macros" ] }
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ use crate::prefixes::{Namespace, Prefix, Prefixes};
|
||||||
use crate::tree_builder::TreeBuilder;
|
use crate::tree_builder::TreeBuilder;
|
||||||
|
|
||||||
use alloc::borrow::Cow;
|
use alloc::borrow::Cow;
|
||||||
use alloc::collections::btree_map::{self, BTreeMap};
|
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
|
@ -30,7 +29,7 @@ use core::str::FromStr;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use rxml::writer::{Encoder, Item, TrackNamespace};
|
use rxml::writer::{Encoder, Item, TrackNamespace};
|
||||||
use rxml::{Namespace as RxmlNamespace, RawReader, XmlVersion};
|
use rxml::{AttrMap, Namespace as RxmlNamespace, NcName, NcNameStr, RawReader, XmlVersion};
|
||||||
|
|
||||||
fn encode_and_write<W: io::Write, T: rxml::writer::TrackNamespace>(
|
fn encode_and_write<W: io::Write, T: rxml::writer::TrackNamespace>(
|
||||||
item: Item<'_>,
|
item: Item<'_>,
|
||||||
|
|
@ -121,7 +120,7 @@ pub struct Element {
|
||||||
namespace: String,
|
namespace: String,
|
||||||
/// Namespace declarations
|
/// Namespace declarations
|
||||||
pub prefixes: Prefixes,
|
pub prefixes: Prefixes,
|
||||||
attributes: BTreeMap<String, String>,
|
attributes: AttrMap,
|
||||||
children: Vec<Node>,
|
children: Vec<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +161,7 @@ impl Element {
|
||||||
name: String,
|
name: String,
|
||||||
namespace: String,
|
namespace: String,
|
||||||
prefixes: P,
|
prefixes: P,
|
||||||
attributes: BTreeMap<String, String>,
|
attributes: AttrMap,
|
||||||
children: Vec<Node>,
|
children: Vec<Node>,
|
||||||
) -> Element {
|
) -> Element {
|
||||||
Element {
|
Element {
|
||||||
|
|
@ -180,16 +179,17 @@ impl Element {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use minidom::Element;
|
/// use minidom::Element;
|
||||||
|
/// use rxml::{Namespace, xml_ncname};
|
||||||
///
|
///
|
||||||
/// let elem = Element::builder("name", "namespace")
|
/// let elem = Element::builder("name", "namespace")
|
||||||
/// .attr("name", "value")
|
/// .attr(xml_ncname!("name").to_owned(), "value")
|
||||||
/// .append("inner")
|
/// .append("inner")
|
||||||
/// .build();
|
/// .build();
|
||||||
///
|
///
|
||||||
/// assert_eq!(elem.name(), "name");
|
/// assert_eq!(elem.name(), "name");
|
||||||
/// assert_eq!(elem.ns(), "namespace".to_owned());
|
/// assert_eq!(elem.ns(), "namespace".to_owned());
|
||||||
/// assert_eq!(elem.attr("name"), Some("value"));
|
/// assert_eq!(elem.attr(xml_ncname!("name")), Some("value"));
|
||||||
/// assert_eq!(elem.attr("inexistent"), None);
|
/// assert_eq!(elem.attr(xml_ncname!("inexistent")), None);
|
||||||
/// assert_eq!(elem.text(), "inner");
|
/// assert_eq!(elem.text(), "inner");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn builder<S: AsRef<str>, NS: Into<String>>(name: S, namespace: NS) -> ElementBuilder {
|
pub fn builder<S: AsRef<str>, NS: Into<String>>(name: S, namespace: NS) -> ElementBuilder {
|
||||||
|
|
@ -198,7 +198,7 @@ impl Element {
|
||||||
name.as_ref().to_string(),
|
name.as_ref().to_string(),
|
||||||
namespace.into(),
|
namespace.into(),
|
||||||
None,
|
None,
|
||||||
BTreeMap::new(),
|
AttrMap::new(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
@ -210,12 +210,13 @@ impl Element {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use minidom::Element;
|
/// use minidom::Element;
|
||||||
|
/// use rxml::{Namespace, xml_ncname};
|
||||||
///
|
///
|
||||||
/// let bare = Element::bare("name", "namespace");
|
/// let bare = Element::bare("name", "namespace");
|
||||||
///
|
///
|
||||||
/// assert_eq!(bare.name(), "name");
|
/// assert_eq!(bare.name(), "name");
|
||||||
/// assert_eq!(bare.ns(), "namespace");
|
/// assert_eq!(bare.ns(), "namespace");
|
||||||
/// assert_eq!(bare.attr("name"), None);
|
/// assert_eq!(bare.attr(xml_ncname!("name")), None);
|
||||||
/// assert_eq!(bare.text(), "");
|
/// assert_eq!(bare.text(), "");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn bare<S: Into<String>, NS: Into<String>>(name: S, namespace: NS) -> Element {
|
pub fn bare<S: Into<String>, NS: Into<String>>(name: S, namespace: NS) -> Element {
|
||||||
|
|
@ -223,7 +224,7 @@ impl Element {
|
||||||
name.into(),
|
name.into(),
|
||||||
namespace.into(),
|
namespace.into(),
|
||||||
None,
|
None,
|
||||||
BTreeMap::new(),
|
AttrMap::new(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -242,8 +243,17 @@ impl Element {
|
||||||
|
|
||||||
/// Returns a reference to the value of the given attribute, if it exists, else `None`.
|
/// Returns a reference to the value of the given attribute, if it exists, else `None`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn attr(&self, name: &str) -> Option<&str> {
|
pub fn attr<'a>(&'a self, name: &'a NcNameStr) -> Option<&'a str> {
|
||||||
if let Some(value) = self.attributes.get(name) {
|
if let Some(value) = self.attributes.get(&RxmlNamespace::NONE, name) {
|
||||||
|
return Some(value);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a reference to the value of the given namespaced attribute, if it exists, else `None`.
|
||||||
|
#[must_use]
|
||||||
|
pub fn attr_ns<'a>(&'a self, ns: &'a RxmlNamespace, name: &'a NcNameStr) -> Option<&'a str> {
|
||||||
|
if let Some(value) = self.attributes.get(ns, name) {
|
||||||
return Some(value);
|
return Some(value);
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
@ -255,43 +265,39 @@ impl Element {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use minidom::Element;
|
/// use minidom::Element;
|
||||||
|
/// use rxml::{Namespace, xml_ncname};
|
||||||
///
|
///
|
||||||
/// let elm: Element = "<elem xmlns=\"ns1\" a=\"b\" />".parse().unwrap();
|
/// let elm: Element = "<elem xmlns=\"ns1\" a=\"b\" />".parse().unwrap();
|
||||||
///
|
///
|
||||||
/// let mut iter = elm.attrs();
|
/// let mut iter = elm.attrs().iter();
|
||||||
///
|
///
|
||||||
/// assert_eq!(iter.next().unwrap(), ("a", "b"));
|
/// assert_eq!(iter.next().unwrap(), ((&Namespace::NONE, &xml_ncname!("a").to_owned()), &String::from("b")));
|
||||||
/// assert_eq!(iter.next(), None);
|
/// assert_eq!(iter.next(), None);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn attrs(&self) -> Attrs<'_> {
|
pub fn attrs(&self) -> &AttrMap {
|
||||||
Attrs {
|
&self.attributes
|
||||||
iter: self.attributes.iter(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over the attributes of this element, with the value being a mutable
|
/// Returns an iterator over the attributes of this element, with the value being a mutable
|
||||||
/// reference.
|
/// reference.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn attrs_mut(&mut self) -> AttrsMut<'_> {
|
pub fn attrs_mut(&mut self) -> &mut AttrMap {
|
||||||
AttrsMut {
|
&mut self.attributes
|
||||||
iter: self.attributes.iter_mut(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifies the value of an attribute.
|
/// Modifies the value of an attribute.
|
||||||
pub fn set_attr<S: Into<String>, V: IntoAttributeValue>(&mut self, name: S, val: V) {
|
pub fn set_attr<V: IntoAttributeValue>(&mut self, ns: RxmlNamespace, name: NcName, val: V) {
|
||||||
let name = name.into();
|
|
||||||
let val = val.into_attribute_value();
|
let val = val.into_attribute_value();
|
||||||
|
|
||||||
if let Some(value) = self.attributes.get_mut(&name) {
|
if let Some(value) = self.attributes.get_mut(&ns, &name) {
|
||||||
*value = val
|
*value = val
|
||||||
.expect("removing existing value via set_attr, this is not yet supported (TODO)"); // TODO
|
.expect("removing existing value via set_attr, this is not yet supported (TODO)"); // TODO
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(val) = val {
|
if let Some(val) = val {
|
||||||
self.attributes.insert(name, val);
|
self.attributes.insert(ns.clone(), name, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,19 +411,8 @@ impl Element {
|
||||||
let namespace: RxmlNamespace = self.namespace.clone().into();
|
let namespace: RxmlNamespace = self.namespace.clone().into();
|
||||||
writer.write(Item::ElementHeadStart(&namespace, (*self.name).try_into()?))?;
|
writer.write(Item::ElementHeadStart(&namespace, (*self.name).try_into()?))?;
|
||||||
|
|
||||||
for (key, value) in &self.attributes {
|
for ((ns, key), value) in &self.attributes {
|
||||||
let (prefix, name) = <&rxml::NameStr>::try_from(&**key)
|
writer.write(Item::Attribute(&ns, key, value))?;
|
||||||
.unwrap()
|
|
||||||
.split_name()
|
|
||||||
.unwrap();
|
|
||||||
let namespace = match prefix {
|
|
||||||
Some(prefix) => match writer.encoder.ns_tracker().lookup_prefix(Some(prefix)) {
|
|
||||||
Ok(v) => v,
|
|
||||||
Err(rxml::writer::PrefixError::Undeclared) => return Err(Error::InvalidPrefix),
|
|
||||||
},
|
|
||||||
None => RxmlNamespace::NONE,
|
|
||||||
};
|
|
||||||
writer.write(Item::Attribute(&namespace, name, value))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.children.is_empty() {
|
if !self.children.is_empty() {
|
||||||
|
|
@ -870,32 +865,6 @@ pub type Nodes<'a> = slice::Iter<'a, Node>;
|
||||||
/// An iterator over mutable references to all child nodes of an `Element`.
|
/// An iterator over mutable references to all child nodes of an `Element`.
|
||||||
pub type NodesMut<'a> = slice::IterMut<'a, Node>;
|
pub type NodesMut<'a> = slice::IterMut<'a, Node>;
|
||||||
|
|
||||||
/// An iterator over the attributes of an `Element`.
|
|
||||||
pub struct Attrs<'a> {
|
|
||||||
iter: btree_map::Iter<'a, String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for Attrs<'a> {
|
|
||||||
type Item = (&'a str, &'a str);
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.iter.next().map(|(x, y)| (x.as_ref(), y.as_ref()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An iterator over the attributes of an `Element`, with the values mutable.
|
|
||||||
pub struct AttrsMut<'a> {
|
|
||||||
iter: btree_map::IterMut<'a, String, String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for AttrsMut<'a> {
|
|
||||||
type Item = (&'a str, &'a mut String);
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.iter.next().map(|(x, y)| (x.as_ref(), y))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A builder for `Element`s.
|
/// A builder for `Element`s.
|
||||||
pub struct ElementBuilder {
|
pub struct ElementBuilder {
|
||||||
root: Element,
|
root: Element,
|
||||||
|
|
@ -917,12 +886,20 @@ impl ElementBuilder {
|
||||||
|
|
||||||
/// Sets an attribute.
|
/// Sets an attribute.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn attr<S: Into<String>, V: IntoAttributeValue>(
|
pub fn attr<V: IntoAttributeValue>(mut self, name: NcName, value: V) -> ElementBuilder {
|
||||||
|
self.root.set_attr(RxmlNamespace::NONE, name, value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets an attribute.
|
||||||
|
#[must_use]
|
||||||
|
pub fn attr_ns<V: IntoAttributeValue>(
|
||||||
mut self,
|
mut self,
|
||||||
name: S,
|
ns: RxmlNamespace,
|
||||||
|
name: NcName,
|
||||||
value: V,
|
value: V,
|
||||||
) -> ElementBuilder {
|
) -> ElementBuilder {
|
||||||
self.root.set_attr(name, value);
|
self.root.set_attr(ns, name, value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -955,21 +932,32 @@ impl ElementBuilder {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use rxml::xml_ncname;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_element_new() {
|
fn test_element_new() {
|
||||||
|
let mut attrs = AttrMap::new();
|
||||||
|
attrs.insert(
|
||||||
|
String::from("namespace").into(),
|
||||||
|
xml_ncname!("name").to_owned(),
|
||||||
|
"value".to_string(),
|
||||||
|
);
|
||||||
let elem = Element::new(
|
let elem = Element::new(
|
||||||
"name".to_owned(),
|
"name".to_owned(),
|
||||||
"namespace".to_owned(),
|
"namespace".to_owned(),
|
||||||
(None, "namespace".to_owned()),
|
(None, "namespace".to_owned()),
|
||||||
BTreeMap::from_iter([("name".to_string(), "value".to_string())].into_iter()),
|
attrs,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(elem.name(), "name");
|
assert_eq!(elem.name(), "name");
|
||||||
assert_eq!(elem.ns(), "namespace".to_owned());
|
assert_eq!(elem.ns(), "namespace".to_owned());
|
||||||
assert_eq!(elem.attr("name"), Some("value"));
|
assert_eq!(
|
||||||
assert_eq!(elem.attr("inexistent"), None);
|
elem.attr_ns(&String::from("namespace").into(), xml_ncname!("name")),
|
||||||
|
Some("value")
|
||||||
|
);
|
||||||
|
assert_eq!(elem.attr(xml_ncname!("inexistent")), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -987,7 +975,9 @@ mod tests {
|
||||||
let xml = b"<foo xmlns='ns1'><bar xmlns='ns1' baz='qxx' /></foo>";
|
let xml = b"<foo xmlns='ns1'><bar xmlns='ns1' baz='qxx' /></foo>";
|
||||||
let elem = Element::from_reader(&xml[..]);
|
let elem = Element::from_reader(&xml[..]);
|
||||||
|
|
||||||
let nested = Element::builder("bar", "ns1").attr("baz", "qxx").build();
|
let nested = Element::builder("bar", "ns1")
|
||||||
|
.attr(xml_ncname!("baz").to_owned(), "qxx")
|
||||||
|
.build();
|
||||||
let elem2 = Element::builder("foo", "ns1").append(nested).build();
|
let elem2 = Element::builder("foo", "ns1").append(nested).build();
|
||||||
|
|
||||||
assert_eq!(elem.unwrap(), elem2);
|
assert_eq!(elem.unwrap(), elem2);
|
||||||
|
|
@ -998,7 +988,9 @@ mod tests {
|
||||||
let xml = b"<foo xmlns='ns1'><prefix:bar xmlns:prefix='ns1' baz='qxx' /></foo>";
|
let xml = b"<foo xmlns='ns1'><prefix:bar xmlns:prefix='ns1' baz='qxx' /></foo>";
|
||||||
let elem = Element::from_reader(&xml[..]);
|
let elem = Element::from_reader(&xml[..]);
|
||||||
|
|
||||||
let nested = Element::builder("bar", "ns1").attr("baz", "qxx").build();
|
let nested = Element::builder("bar", "ns1")
|
||||||
|
.attr(xml_ncname!("baz").to_owned(), "qxx")
|
||||||
|
.build();
|
||||||
let elem2 = Element::builder("foo", "ns1").append(nested).build();
|
let elem2 = Element::builder("foo", "ns1").append(nested).build();
|
||||||
|
|
||||||
assert_eq!(elem.unwrap(), elem2);
|
assert_eq!(elem.unwrap(), elem2);
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,23 @@ use alloc::format;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
use rxml::{xml_ncname, Namespace as RxmlNamespace};
|
||||||
|
|
||||||
const TEST_STRING: &'static [u8] = br#"<root xmlns='root_ns' a='b' xml:lang='en'>meow<child c='d'/><child xmlns='child_ns' d='e' xml:lang='fr'/>nya</root>"#;
|
const TEST_STRING: &'static [u8] = br#"<root xmlns='root_ns' a='b' xml:lang='en'>meow<child c='d'/><child xmlns='child_ns' d='e' xml:lang='fr'/>nya</root>"#;
|
||||||
|
|
||||||
fn build_test_tree() -> Element {
|
fn build_test_tree() -> Element {
|
||||||
let mut root = Element::builder("root", "root_ns")
|
let mut root = Element::builder("root", "root_ns")
|
||||||
.attr("xml:lang", "en")
|
.attr_ns(RxmlNamespace::XML, xml_ncname!("lang").to_owned(), "en")
|
||||||
.attr("a", "b")
|
.attr(xml_ncname!("a").to_owned(), "b")
|
||||||
.build();
|
.build();
|
||||||
root.append_text_node("meow");
|
root.append_text_node("meow");
|
||||||
let child = Element::builder("child", "root_ns").attr("c", "d").build();
|
let child = Element::builder("child", "root_ns")
|
||||||
|
.attr(xml_ncname!("c").to_owned(), "d")
|
||||||
|
.build();
|
||||||
root.append_child(child);
|
root.append_child(child);
|
||||||
let other_child = Element::builder("child", "child_ns")
|
let other_child = Element::builder("child", "child_ns")
|
||||||
.attr("d", "e")
|
.attr(xml_ncname!("d").to_owned(), "e")
|
||||||
.attr("xml:lang", "fr")
|
.attr_ns(RxmlNamespace::XML, xml_ncname!("lang").to_owned(), "fr")
|
||||||
.build();
|
.build();
|
||||||
root.append_child(other_child);
|
root.append_child(other_child);
|
||||||
root.append_text_node("nya");
|
root.append_text_node("nya");
|
||||||
|
|
@ -243,7 +247,7 @@ fn writer_with_prefix_deduplicate() {
|
||||||
#[test]
|
#[test]
|
||||||
fn writer_escapes_attributes() {
|
fn writer_escapes_attributes() {
|
||||||
let root = Element::builder("root", "ns1")
|
let root = Element::builder("root", "ns1")
|
||||||
.attr("a", "\"Air\" quotes")
|
.attr(xml_ncname!("a").to_owned(), "\"Air\" quotes")
|
||||||
.build();
|
.build();
|
||||||
let mut writer = Vec::new();
|
let mut writer = Vec::new();
|
||||||
{
|
{
|
||||||
|
|
@ -271,14 +275,14 @@ fn writer_escapes_text() {
|
||||||
#[test]
|
#[test]
|
||||||
fn builder_works() {
|
fn builder_works() {
|
||||||
let elem = Element::builder("a", "b")
|
let elem = Element::builder("a", "b")
|
||||||
.attr("c", "d")
|
.attr(xml_ncname!("c").to_owned(), "d")
|
||||||
.append(Element::builder("child", "b"))
|
.append(Element::builder("child", "b"))
|
||||||
.append("e")
|
.append("e")
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(elem.name(), "a");
|
assert_eq!(elem.name(), "a");
|
||||||
assert_eq!(elem.ns(), "b".to_owned());
|
assert_eq!(elem.ns(), "b".to_owned());
|
||||||
assert_eq!(elem.attr("c"), Some("d"));
|
assert_eq!(elem.attr(xml_ncname!("c")), Some("d"));
|
||||||
assert_eq!(elem.attr("x"), None);
|
assert_eq!(elem.attr(xml_ncname!("x")), None);
|
||||||
assert_eq!(elem.text(), "e");
|
assert_eq!(elem.text(), "e");
|
||||||
assert!(elem.has_child("child", "b"));
|
assert!(elem.has_child("child", "b"));
|
||||||
assert!(elem.is("a", "b"));
|
assert!(elem.is("a", "b"));
|
||||||
|
|
@ -307,11 +311,15 @@ fn get_child_works() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is("child", "child_ns"));
|
.is("child", "child_ns"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
root.get_child("child", "root_ns").unwrap().attr("c"),
|
root.get_child("child", "root_ns")
|
||||||
|
.unwrap()
|
||||||
|
.attr(xml_ncname!("c")),
|
||||||
Some("d")
|
Some("d")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
root.get_child("child", "child_ns").unwrap().attr("d"),
|
root.get_child("child", "child_ns")
|
||||||
|
.unwrap()
|
||||||
|
.attr(xml_ncname!("d")),
|
||||||
Some("e")
|
Some("e")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -349,12 +357,15 @@ fn two_elements_with_same_arguments_different_order_are_equal() {
|
||||||
#[test]
|
#[test]
|
||||||
fn namespace_attributes_works() {
|
fn namespace_attributes_works() {
|
||||||
let root = Element::from_reader(TEST_STRING).unwrap();
|
let root = Element::from_reader(TEST_STRING).unwrap();
|
||||||
assert_eq!("en", root.attr("xml:lang").unwrap());
|
assert_eq!(
|
||||||
|
Some("en"),
|
||||||
|
root.attr_ns(RxmlNamespace::xml(), xml_ncname!("lang"))
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"fr",
|
"fr",
|
||||||
root.get_child("child", "child_ns")
|
root.get_child("child", "child_ns")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.attr("xml:lang")
|
.attr_ns(RxmlNamespace::xml(), xml_ncname!("lang"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// Copyright (c) 2022 Astro <astro@spaceboyz.net>
|
// Copyright (c) 2022 Astro <astro@spaceboyz.net>
|
||||||
|
// Copyright (c) 2025 pep <pep@bouah.net>
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
|
@ -8,19 +9,18 @@
|
||||||
|
|
||||||
use crate::prefixes::{Prefix, Prefixes};
|
use crate::prefixes::{Prefix, Prefixes};
|
||||||
use crate::{Element, Error};
|
use crate::{Element, Error};
|
||||||
use alloc::collections::BTreeMap;
|
|
||||||
use alloc::format;
|
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use rxml::RawEvent;
|
use rxml::{AttrMap, Namespace, RawEvent};
|
||||||
|
|
||||||
/// Tree-building parser state
|
/// Tree-building parser state
|
||||||
pub struct TreeBuilder {
|
pub struct TreeBuilder {
|
||||||
next_tag: Option<(Prefix, String, Prefixes, BTreeMap<String, String>)>,
|
next_tag: Option<(Prefix, String, Prefixes, AttrMap)>,
|
||||||
/// Parsing stack
|
/// Parsing stack
|
||||||
stack: Vec<Element>,
|
stack: Vec<Element>,
|
||||||
/// Namespace set stack by prefix
|
/// Namespace set stack by prefix
|
||||||
prefixes_stack: Vec<Prefixes>,
|
prefixes_stack: Vec<Prefixes>,
|
||||||
|
attrs_stack: Vec<(String, String, String)>,
|
||||||
/// Document root element if finished
|
/// Document root element if finished
|
||||||
pub root: Option<Element>,
|
pub root: Option<Element>,
|
||||||
}
|
}
|
||||||
|
|
@ -39,6 +39,7 @@ impl TreeBuilder {
|
||||||
next_tag: None,
|
next_tag: None,
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
prefixes_stack: Vec::new(),
|
prefixes_stack: Vec::new(),
|
||||||
|
attrs_stack: Vec::new(),
|
||||||
root: None,
|
root: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -83,8 +84,11 @@ impl TreeBuilder {
|
||||||
|
|
||||||
/// Lookup XML namespace declaration for given prefix (or no prefix)
|
/// Lookup XML namespace declaration for given prefix (or no prefix)
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn lookup_prefix(&self, prefix: &Option<String>) -> Option<&str> {
|
fn lookup_prefix<'a>(
|
||||||
for nss in self.prefixes_stack.iter().rev() {
|
prefixes_stack: &'a Vec<Prefixes>,
|
||||||
|
prefix: &'a Option<String>,
|
||||||
|
) -> Option<&'a str> {
|
||||||
|
for nss in prefixes_stack.iter().rev() {
|
||||||
if let Some(ns) = nss.get(prefix) {
|
if let Some(ns) = nss.get(prefix) {
|
||||||
return Some(ns);
|
return Some(ns);
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +133,7 @@ impl TreeBuilder {
|
||||||
prefix.map(|prefix| prefix.as_str().to_owned()),
|
prefix.map(|prefix| prefix.as_str().to_owned()),
|
||||||
name.as_str().to_owned(),
|
name.as_str().to_owned(),
|
||||||
prefixes,
|
prefixes,
|
||||||
BTreeMap::new(),
|
AttrMap::new(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,23 +145,47 @@ impl TreeBuilder {
|
||||||
prefixes.insert(Some(prefix.as_str().to_owned()), value);
|
prefixes.insert(Some(prefix.as_str().to_owned()), value);
|
||||||
}
|
}
|
||||||
(Some(prefix), name) => {
|
(Some(prefix), name) => {
|
||||||
attrs.insert(format!("{prefix}:{name}"), value.as_str().to_owned());
|
self.attrs_stack
|
||||||
|
.push((prefix.to_string(), name.to_string(), value));
|
||||||
}
|
}
|
||||||
(None, name) => {
|
(None, name) => {
|
||||||
attrs.insert(name.as_str().to_owned(), value.as_str().to_owned());
|
attrs.insert(
|
||||||
|
Namespace::NONE,
|
||||||
|
name.try_into().unwrap(),
|
||||||
|
value.as_str().to_owned(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RawEvent::ElementHeadClose(_) => {
|
RawEvent::ElementHeadClose(_) => {
|
||||||
if let Some((prefix, name, prefixes, attrs)) = self.next_tag.take() {
|
if let Some((prefix, name, prefixes, mut attrs)) = self.next_tag.take() {
|
||||||
self.prefixes_stack.push(prefixes.clone());
|
self.prefixes_stack.push(prefixes.clone());
|
||||||
|
|
||||||
let namespace = self
|
let namespace = TreeBuilder::lookup_prefix(
|
||||||
.lookup_prefix(&prefix.map(|prefix| prefix.as_str().to_owned()))
|
&self.prefixes_stack,
|
||||||
.ok_or(Error::MissingNamespace)?
|
&prefix.map(|prefix| prefix.as_str().to_owned()),
|
||||||
.to_owned();
|
)
|
||||||
|
.ok_or(Error::MissingNamespace)?
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
|
for (prefix, attr, value) in self.attrs_stack.drain(..) {
|
||||||
|
let ns = if prefix == "xml" {
|
||||||
|
rxml::Namespace::xml()
|
||||||
|
} else {
|
||||||
|
&TreeBuilder::lookup_prefix(
|
||||||
|
&self.prefixes_stack,
|
||||||
|
&Some(prefix.to_string()),
|
||||||
|
)
|
||||||
|
.map(String::from)
|
||||||
|
.map(|s| TryInto::<Namespace>::try_into(s).unwrap())
|
||||||
|
.ok_or(Error::MissingNamespace)?
|
||||||
|
.to_owned()
|
||||||
|
};
|
||||||
|
attrs.insert(ns.clone(), attr.try_into().unwrap(), value.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
let el = Element::new(name.to_owned(), namespace, prefixes, attrs, Vec::new());
|
let el = Element::new(name.to_owned(), namespace, prefixes, attrs, Vec::new());
|
||||||
self.stack.push(el);
|
self.stack.push(el);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ mod tests {
|
||||||
let query = ServicesQuery { type_: None };
|
let query = ServicesQuery { type_: None };
|
||||||
let elem = Element::from(query);
|
let elem = Element::from(query);
|
||||||
assert!(elem.is("services", ns::EXT_DISCO));
|
assert!(elem.is("services", ns::EXT_DISCO));
|
||||||
assert_eq!(elem.attrs().next(), None);
|
assert_eq!(elem.attrs().into_iter().next(), None);
|
||||||
assert_eq!(elem.nodes().next(), None);
|
assert_eq!(elem.nodes().next(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
use xso::exports::rxml;
|
||||||
use xso::{
|
use xso::{
|
||||||
error::{Error, FromElementError},
|
error::{Error, FromElementError},
|
||||||
AsXml, FromXml,
|
AsXml, FromXml,
|
||||||
|
|
@ -254,9 +255,9 @@ impl TryFrom<Element> for Transport {
|
||||||
impl From<Transport> for Element {
|
impl From<Transport> for Element {
|
||||||
fn from(transport: Transport) -> Element {
|
fn from(transport: Transport) -> Element {
|
||||||
Element::builder("transport", ns::JINGLE_S5B)
|
Element::builder("transport", ns::JINGLE_S5B)
|
||||||
.attr("sid", transport.sid)
|
.attr(rxml::xml_ncname!("sid").into(), transport.sid)
|
||||||
.attr("dstaddr", transport.dstaddr)
|
.attr(rxml::xml_ncname!("dstaddr").into(), transport.dstaddr)
|
||||||
.attr("mode", transport.mode)
|
.attr(rxml::xml_ncname!("mode").into(), transport.mode)
|
||||||
.append_all(match transport.payload {
|
.append_all(match transport.payload {
|
||||||
TransportPayload::Candidates(candidates) => candidates
|
TransportPayload::Candidates(candidates) => candidates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -264,7 +265,7 @@ impl From<Transport> for Element {
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
TransportPayload::Activated(cid) => {
|
TransportPayload::Activated(cid) => {
|
||||||
vec![Element::builder("activated", ns::JINGLE_S5B)
|
vec![Element::builder("activated", ns::JINGLE_S5B)
|
||||||
.attr("cid", cid)
|
.attr(rxml::xml_ncname!("cid").into(), cid)
|
||||||
.build()]
|
.build()]
|
||||||
}
|
}
|
||||||
TransportPayload::CandidateError => {
|
TransportPayload::CandidateError => {
|
||||||
|
|
@ -272,7 +273,7 @@ impl From<Transport> for Element {
|
||||||
}
|
}
|
||||||
TransportPayload::CandidateUsed(cid) => {
|
TransportPayload::CandidateUsed(cid) => {
|
||||||
vec![Element::builder("candidate-used", ns::JINGLE_S5B)
|
vec![Element::builder("candidate-used", ns::JINGLE_S5B)
|
||||||
.attr("cid", cid)
|
.attr(rxml::xml_ncname!("cid").into(), cid)
|
||||||
.build()]
|
.build()]
|
||||||
}
|
}
|
||||||
TransportPayload::ProxyError => {
|
TransportPayload::ProxyError => {
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use jid::{BareJid, FullJid};
|
use jid::{BareJid, FullJid};
|
||||||
use xso::error::FromElementError;
|
use xso::error::FromElementError;
|
||||||
|
use xso::exports::rxml;
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -602,25 +603,31 @@ mod tests {
|
||||||
fn presence_with_to() {
|
fn presence_with_to() {
|
||||||
let presence = Presence::new(Type::None);
|
let presence = Presence::new(Type::None);
|
||||||
let elem: Element = presence.into();
|
let elem: Element = presence.into();
|
||||||
assert_eq!(elem.attr("to"), None);
|
assert_eq!(elem.attr(rxml::xml_ncname!("to")), None);
|
||||||
|
|
||||||
let presence = Presence::new(Type::None).with_to(Jid::new("localhost").unwrap());
|
let presence = Presence::new(Type::None).with_to(Jid::new("localhost").unwrap());
|
||||||
let elem: Element = presence.into();
|
let elem: Element = presence.into();
|
||||||
assert_eq!(elem.attr("to"), Some("localhost"));
|
assert_eq!(elem.attr(rxml::xml_ncname!("to")), Some("localhost"));
|
||||||
|
|
||||||
let presence = Presence::new(Type::None).with_to(BareJid::new("localhost").unwrap());
|
let presence = Presence::new(Type::None).with_to(BareJid::new("localhost").unwrap());
|
||||||
let elem: Element = presence.into();
|
let elem: Element = presence.into();
|
||||||
assert_eq!(elem.attr("to"), Some("localhost"));
|
assert_eq!(elem.attr(rxml::xml_ncname!("to")), Some("localhost"));
|
||||||
|
|
||||||
let presence =
|
let presence =
|
||||||
Presence::new(Type::None).with_to(Jid::new("test@localhost/coucou").unwrap());
|
Presence::new(Type::None).with_to(Jid::new("test@localhost/coucou").unwrap());
|
||||||
let elem: Element = presence.into();
|
let elem: Element = presence.into();
|
||||||
assert_eq!(elem.attr("to"), Some("test@localhost/coucou"));
|
assert_eq!(
|
||||||
|
elem.attr(rxml::xml_ncname!("to")),
|
||||||
|
Some("test@localhost/coucou")
|
||||||
|
);
|
||||||
|
|
||||||
let presence =
|
let presence =
|
||||||
Presence::new(Type::None).with_to(FullJid::new("test@localhost/coucou").unwrap());
|
Presence::new(Type::None).with_to(FullJid::new("test@localhost/coucou").unwrap());
|
||||||
let elem: Element = presence.into();
|
let elem: Element = presence.into();
|
||||||
assert_eq!(elem.attr("to"), Some("test@localhost/coucou"));
|
assert_eq!(
|
||||||
|
elem.attr(rxml::xml_ncname!("to")),
|
||||||
|
Some("test@localhost/coucou")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ mod tests {
|
||||||
use crate::ns;
|
use crate::ns;
|
||||||
use minidom::Element;
|
use minidom::Element;
|
||||||
use xso::error::{Error, FromElementError};
|
use xso::error::{Error, FromElementError};
|
||||||
|
use xso::exports::rxml;
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -80,13 +81,13 @@ mod tests {
|
||||||
let receipt = Request;
|
let receipt = Request;
|
||||||
let elem: Element = receipt.into();
|
let elem: Element = receipt.into();
|
||||||
assert!(elem.is("request", ns::RECEIPTS));
|
assert!(elem.is("request", ns::RECEIPTS));
|
||||||
assert_eq!(elem.attrs().count(), 0);
|
assert_eq!(elem.attrs().into_iter().count(), 0);
|
||||||
|
|
||||||
let receipt = Received {
|
let receipt = Received {
|
||||||
id: String::from("coucou"),
|
id: String::from("coucou"),
|
||||||
};
|
};
|
||||||
let elem: Element = receipt.into();
|
let elem: Element = receipt.into();
|
||||||
assert!(elem.is("received", ns::RECEIPTS));
|
assert!(elem.is("received", ns::RECEIPTS));
|
||||||
assert_eq!(elem.attr("id"), Some("coucou"));
|
assert_eq!(elem.attr(rxml::xml_ncname!("id")), Some("coucou"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ mod helpers {
|
||||||
|
|
||||||
use self::helpers::{parse_str, roundtrip_full};
|
use self::helpers::{parse_str, roundtrip_full};
|
||||||
|
|
||||||
|
use xso::exports::rxml;
|
||||||
use xso::{AsXml, FromXml, PrintRawXml};
|
use xso::{AsXml, FromXml, PrintRawXml};
|
||||||
|
|
||||||
// these are adverserial local names in order to trigger any issues with
|
// these are adverserial local names in order to trigger any issues with
|
||||||
|
|
@ -1790,9 +1791,9 @@ fn element_catch_one_and_many_parse_in_order() {
|
||||||
"<parent xmlns='urn:example:ns1'><child num='0'/><child num='1'/></parent>",
|
"<parent xmlns='urn:example:ns1'><child num='0'/><child num='1'/></parent>",
|
||||||
) {
|
) {
|
||||||
Ok(ElementCatchOneAndMany { child, children }) => {
|
Ok(ElementCatchOneAndMany { child, children }) => {
|
||||||
assert_eq!(child.attr("num"), Some("0"));
|
assert_eq!(child.attr(rxml::xml_ncname!("num")), Some("0"));
|
||||||
assert_eq!(children.len(), 1);
|
assert_eq!(children.len(), 1);
|
||||||
assert_eq!(children[0].attr("num"), Some("1"));
|
assert_eq!(children[0].attr(rxml::xml_ncname!("num")), Some("1"));
|
||||||
}
|
}
|
||||||
other => panic!("unexpected result: {:?}", other),
|
other => panic!("unexpected result: {:?}", other),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ macro_rules! get_attr {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
($elem:ident, $attr:tt, Option, $value:ident, $func:expr) => {
|
($elem:ident, $attr:tt, Option, $value:ident, $func:expr) => {
|
||||||
match $elem.attr($attr) {
|
match $elem.attr(::xso::exports::rxml::xml_ncname!($attr).into()) {
|
||||||
Some($value) => Some($func),
|
Some($value) => Some($func),
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($elem:ident, $attr:tt, Required, $value:ident, $func:expr) => {
|
($elem:ident, $attr:tt, Required, $value:ident, $func:expr) => {
|
||||||
match $elem.attr($attr) {
|
match $elem.attr(::xso::exports::rxml::xml_ncname!($attr).into()) {
|
||||||
Some($value) => $func,
|
Some($value) => $func,
|
||||||
None => {
|
None => {
|
||||||
return Err(xso::error::Error::Other(
|
return Err(xso::error::Error::Other(
|
||||||
|
|
@ -32,7 +32,7 @@ macro_rules! get_attr {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($elem:ident, $attr:tt, Default, $value:ident, $func:expr) => {
|
($elem:ident, $attr:tt, Default, $value:ident, $func:expr) => {
|
||||||
match $elem.attr($attr) {
|
match $elem.attr(::xso::exports::rxml::xml_ncname!($attr).into()) {
|
||||||
Some($value) => $func,
|
Some($value) => $func,
|
||||||
None => ::core::default::Default::default(),
|
None => ::core::default::Default::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +277,7 @@ macro_rules! generate_attribute_enum {
|
||||||
impl From<$elem> for minidom::Element {
|
impl From<$elem> for minidom::Element {
|
||||||
fn from(elem: $elem) -> minidom::Element {
|
fn from(elem: $elem) -> minidom::Element {
|
||||||
minidom::Element::builder($name, crate::ns::$ns)
|
minidom::Element::builder($name, crate::ns::$ns)
|
||||||
.attr($attr, match elem {
|
.attr(::xso::exports::rxml::xml_ncname!($attr).into(), match elem {
|
||||||
$($elem::$enum => $enum_name,)+
|
$($elem::$enum => $enum_name,)+
|
||||||
})
|
})
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -343,9 +343,9 @@ macro_rules! check_no_attributes {
|
||||||
macro_rules! check_no_unknown_attributes {
|
macro_rules! check_no_unknown_attributes {
|
||||||
($elem:ident, $name:tt, [$($attr:tt),*]) => (
|
($elem:ident, $name:tt, [$($attr:tt),*]) => (
|
||||||
#[cfg(not(feature = "disable-validation"))]
|
#[cfg(not(feature = "disable-validation"))]
|
||||||
for (_attr, _) in $elem.attrs() {
|
for ((ns, attr), _) in $elem.attrs() {
|
||||||
$(
|
$(
|
||||||
if _attr == $attr {
|
if *ns == ::xso::exports::rxml::Namespace::NONE && attr == $attr {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,11 @@ use crate::message::MessagePayload;
|
||||||
use crate::ns;
|
use crate::ns;
|
||||||
use alloc::collections::BTreeMap;
|
use alloc::collections::BTreeMap;
|
||||||
use minidom::{Element, Node};
|
use minidom::{Element, Node};
|
||||||
use xso::error::{Error, FromElementError};
|
use xso::exports::rxml;
|
||||||
|
use xso::{
|
||||||
|
error::{Error, FromElementError},
|
||||||
|
exports::rxml::Namespace,
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Use a proper lang type.
|
// TODO: Use a proper lang type.
|
||||||
type Lang = String;
|
type Lang = String;
|
||||||
|
|
@ -72,7 +76,10 @@ impl TryFrom<Element> for XhtmlIm {
|
||||||
for child in elem.children() {
|
for child in elem.children() {
|
||||||
if child.is("body", ns::XHTML) {
|
if child.is("body", ns::XHTML) {
|
||||||
let child = child.clone();
|
let child = child.clone();
|
||||||
let lang = child.attr("xml:lang").unwrap_or("").to_string();
|
let lang = child
|
||||||
|
.attr_ns(rxml::Namespace::xml(), rxml::xml_ncname!("lang").into())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string();
|
||||||
let body = Body::try_from(child)?;
|
let body = Body::try_from(child)?;
|
||||||
match bodies.insert(lang, body) {
|
match bodies.insert(lang, body) {
|
||||||
None => (),
|
None => (),
|
||||||
|
|
@ -161,8 +168,13 @@ impl TryFrom<Element> for Body {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Body {
|
Ok(Body {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
xml_lang: elem.attr("xml:lang").map(|xml_lang| xml_lang.to_string()),
|
xml_lang: elem
|
||||||
|
.attr_ns(
|
||||||
|
&Into::<Namespace>::into(String::from("xml")),
|
||||||
|
rxml::xml_ncname!("lang").into(),
|
||||||
|
)
|
||||||
|
.map(|xml_lang| xml_lang.to_string()),
|
||||||
children,
|
children,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -171,8 +183,15 @@ impl TryFrom<Element> for Body {
|
||||||
impl From<Body> for Element {
|
impl From<Body> for Element {
|
||||||
fn from(body: Body) -> Element {
|
fn from(body: Body) -> Element {
|
||||||
Element::builder("body", ns::XHTML)
|
Element::builder("body", ns::XHTML)
|
||||||
.attr("style", get_style_string(body.style))
|
.attr(
|
||||||
.attr("xml:lang", body.xml_lang)
|
rxml::xml_ncname!("style").into(),
|
||||||
|
get_style_string(body.style),
|
||||||
|
)
|
||||||
|
.attr_ns(
|
||||||
|
Into::<Namespace>::into(String::from("xml")),
|
||||||
|
rxml::xml_ncname!("lang").into(),
|
||||||
|
body.xml_lang,
|
||||||
|
)
|
||||||
.append_all(children_to_nodes(body.children))
|
.append_all(children_to_nodes(body.children))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
@ -309,44 +328,52 @@ impl TryFrom<Element> for Tag {
|
||||||
|
|
||||||
Ok(match elem.name() {
|
Ok(match elem.name() {
|
||||||
"a" => Tag::A {
|
"a" => Tag::A {
|
||||||
href: elem.attr("href").map(|href| href.to_string()),
|
href: elem
|
||||||
style: parse_css(elem.attr("style")),
|
.attr(rxml::xml_ncname!("href"))
|
||||||
type_: elem.attr("type").map(|type_| type_.to_string()),
|
.map(|href| href.to_string()),
|
||||||
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
|
type_: elem
|
||||||
|
.attr(rxml::xml_ncname!("type"))
|
||||||
|
.map(|type_| type_.to_string()),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"blockquote" => Tag::Blockquote {
|
"blockquote" => Tag::Blockquote {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"br" => Tag::Br,
|
"br" => Tag::Br,
|
||||||
"cite" => Tag::Cite {
|
"cite" => Tag::Cite {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"em" => Tag::Em { children },
|
"em" => Tag::Em { children },
|
||||||
"img" => Tag::Img {
|
"img" => Tag::Img {
|
||||||
src: elem.attr("src").map(|src| src.to_string()),
|
src: elem
|
||||||
alt: elem.attr("alt").map(|alt| alt.to_string()),
|
.attr(rxml::xml_ncname!("src"))
|
||||||
|
.map(|src| src.to_string()),
|
||||||
|
alt: elem
|
||||||
|
.attr(rxml::xml_ncname!("alt"))
|
||||||
|
.map(|alt| alt.to_string()),
|
||||||
},
|
},
|
||||||
"li" => Tag::Li {
|
"li" => Tag::Li {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"ol" => Tag::Ol {
|
"ol" => Tag::Ol {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"p" => Tag::P {
|
"p" => Tag::P {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"span" => Tag::Span {
|
"span" => Tag::Span {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
"strong" => Tag::Strong { children },
|
"strong" => Tag::Strong { children },
|
||||||
"ul" => Tag::Ul {
|
"ul" => Tag::Ul {
|
||||||
style: parse_css(elem.attr("style")),
|
style: parse_css(elem.attr(rxml::xml_ncname!("style"))),
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
_ => Tag::Unknown(children),
|
_ => Tag::Unknown(children),
|
||||||
|
|
@ -367,13 +394,13 @@ impl From<Tag> for Element {
|
||||||
{
|
{
|
||||||
let mut attrs = vec![];
|
let mut attrs = vec![];
|
||||||
if let Some(href) = href {
|
if let Some(href) = href {
|
||||||
attrs.push(("href", href));
|
attrs.push((rxml::xml_ncname!("href"), href));
|
||||||
}
|
}
|
||||||
if let Some(style) = get_style_string(style) {
|
if let Some(style) = get_style_string(style) {
|
||||||
attrs.push(("style", style));
|
attrs.push((rxml::xml_ncname!("style"), style));
|
||||||
}
|
}
|
||||||
if let Some(type_) = type_ {
|
if let Some(type_) = type_ {
|
||||||
attrs.push(("type", type_));
|
attrs.push((rxml::xml_ncname!("type"), type_));
|
||||||
}
|
}
|
||||||
attrs
|
attrs
|
||||||
},
|
},
|
||||||
|
|
@ -382,7 +409,7 @@ impl From<Tag> for Element {
|
||||||
Tag::Blockquote { style, children } => (
|
Tag::Blockquote { style, children } => (
|
||||||
"blockquote",
|
"blockquote",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -391,7 +418,7 @@ impl From<Tag> for Element {
|
||||||
Tag::Cite { style, children } => (
|
Tag::Cite { style, children } => (
|
||||||
"cite",
|
"cite",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -400,17 +427,17 @@ impl From<Tag> for Element {
|
||||||
Tag::Img { src, alt } => {
|
Tag::Img { src, alt } => {
|
||||||
let mut attrs = vec![];
|
let mut attrs = vec![];
|
||||||
if let Some(src) = src {
|
if let Some(src) = src {
|
||||||
attrs.push(("src", src));
|
attrs.push((rxml::xml_ncname!("src"), src));
|
||||||
}
|
}
|
||||||
if let Some(alt) = alt {
|
if let Some(alt) = alt {
|
||||||
attrs.push(("alt", alt));
|
attrs.push((rxml::xml_ncname!("alt"), alt));
|
||||||
}
|
}
|
||||||
("img", attrs, vec![])
|
("img", attrs, vec![])
|
||||||
}
|
}
|
||||||
Tag::Li { style, children } => (
|
Tag::Li { style, children } => (
|
||||||
"li",
|
"li",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -418,7 +445,7 @@ impl From<Tag> for Element {
|
||||||
Tag::Ol { style, children } => (
|
Tag::Ol { style, children } => (
|
||||||
"ol",
|
"ol",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -426,7 +453,7 @@ impl From<Tag> for Element {
|
||||||
Tag::P { style, children } => (
|
Tag::P { style, children } => (
|
||||||
"p",
|
"p",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -434,7 +461,7 @@ impl From<Tag> for Element {
|
||||||
Tag::Span { style, children } => (
|
Tag::Span { style, children } => (
|
||||||
"span",
|
"span",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -443,7 +470,7 @@ impl From<Tag> for Element {
|
||||||
Tag::Ul { style, children } => (
|
Tag::Ul { style, children } => (
|
||||||
"ul",
|
"ul",
|
||||||
match get_style_string(style) {
|
match get_style_string(style) {
|
||||||
Some(style) => vec![("style", style)],
|
Some(style) => vec![(rxml::xml_ncname!("style"), style)],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
},
|
},
|
||||||
children,
|
children,
|
||||||
|
|
@ -454,7 +481,7 @@ impl From<Tag> for Element {
|
||||||
};
|
};
|
||||||
let mut builder = Element::builder(name, ns::XHTML).append_all(children_to_nodes(children));
|
let mut builder = Element::builder(name, ns::XHTML).append_all(children_to_nodes(children));
|
||||||
for (key, value) in attrs {
|
for (key, value) in attrs {
|
||||||
builder = builder.attr(key, value);
|
builder = builder.attr(key.into(), value);
|
||||||
}
|
}
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,7 @@ use core::marker::PhantomData;
|
||||||
|
|
||||||
use minidom::{Element, Node};
|
use minidom::{Element, Node};
|
||||||
|
|
||||||
use rxml::{
|
use rxml::{parser::EventMetrics, AttrMap, Event, Namespace, NcName, NcNameStr};
|
||||||
parser::EventMetrics,
|
|
||||||
writer::{SimpleNamespaces, TrackNamespace},
|
|
||||||
AttrMap, Event, Name, NameStr, Namespace, NcName, NcNameStr,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{Error, FromEventsError},
|
error::{Error, FromEventsError},
|
||||||
|
|
@ -74,26 +70,8 @@ pub fn make_start_ev_parts(el: &Element) -> Result<(rxml::QName, AttrMap), Error
|
||||||
let namespace = Namespace::from(el.ns());
|
let namespace = Namespace::from(el.ns());
|
||||||
|
|
||||||
let mut attrs = AttrMap::new();
|
let mut attrs = AttrMap::new();
|
||||||
for (name, value) in el.attrs() {
|
for ((namespace, name), value) in el.attrs() {
|
||||||
let name = Name::try_from(name)?;
|
attrs.insert(namespace.clone(), name.clone(), value.to_owned());
|
||||||
let (prefix, name) = name.split_name()?;
|
|
||||||
let namespace = if let Some(prefix) = prefix {
|
|
||||||
if prefix == "xml" {
|
|
||||||
Namespace::XML
|
|
||||||
} else {
|
|
||||||
let ns = match el.prefixes.get(&Some(prefix.into())) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => {
|
|
||||||
panic!("undeclared xml namespace prefix in minidom::Element")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Namespace::from(ns.to_owned())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Namespace::NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
attrs.insert(namespace, name, value.to_owned());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(((namespace, name), attrs))
|
Ok(((namespace, name), attrs))
|
||||||
|
|
@ -178,7 +156,7 @@ enum AsXmlState<'a> {
|
||||||
element: &'a Element,
|
element: &'a Element,
|
||||||
|
|
||||||
/// Attribute iterator.
|
/// Attribute iterator.
|
||||||
attributes: minidom::element::Attrs<'a>,
|
attributes: rxml::xml_map::Iter<'a, std::string::String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Content: The contents of the element are streamed as events.
|
/// Content: The contents of the element are streamed as events.
|
||||||
|
|
@ -218,7 +196,7 @@ impl<'a> Iterator for ElementAsXml<'a> {
|
||||||
);
|
);
|
||||||
self.0 = Some(AsXmlState::Attributes {
|
self.0 = Some(AsXmlState::Attributes {
|
||||||
element,
|
element,
|
||||||
attributes: element.attrs(),
|
attributes: element.attrs().iter(),
|
||||||
});
|
});
|
||||||
Some(Ok(item))
|
Some(Ok(item))
|
||||||
}
|
}
|
||||||
|
|
@ -226,38 +204,9 @@ impl<'a> Iterator for ElementAsXml<'a> {
|
||||||
ref mut attributes,
|
ref mut attributes,
|
||||||
element,
|
element,
|
||||||
}) => {
|
}) => {
|
||||||
if let Some((name, value)) = attributes.next() {
|
if let Some(((namespace, name), value)) = attributes.next() {
|
||||||
let name = match <&NameStr>::try_from(name) {
|
|
||||||
Ok(v) => v,
|
|
||||||
Err(e) => {
|
|
||||||
self.0 = None;
|
|
||||||
return Some(Err(e.into()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let (prefix, name) = match name.split_name() {
|
|
||||||
Ok(v) => v,
|
|
||||||
Err(e) => {
|
|
||||||
self.0 = None;
|
|
||||||
return Some(Err(e.into()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let namespace = if let Some(prefix) = prefix {
|
|
||||||
if prefix == "xml" {
|
|
||||||
Namespace::XML
|
|
||||||
} else {
|
|
||||||
let ns = match element.prefixes.get(&Some(prefix.as_str().to_owned())) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => {
|
|
||||||
panic!("undeclared xml namespace prefix in minidom::Element")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Namespace::from(ns.to_owned())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Namespace::NONE
|
|
||||||
};
|
|
||||||
Some(Ok(Item::Attribute(
|
Some(Ok(Item::Attribute(
|
||||||
namespace,
|
namespace.clone(),
|
||||||
Cow::Borrowed(name),
|
Cow::Borrowed(name),
|
||||||
Cow::Borrowed(value),
|
Cow::Borrowed(value),
|
||||||
)))
|
)))
|
||||||
|
|
@ -330,24 +279,9 @@ impl ElementFromEvents {
|
||||||
/// [`minidom::Element`], this is contractually infallible. Using this may
|
/// [`minidom::Element`], this is contractually infallible. Using this may
|
||||||
/// thus save you an `unwrap()` call.
|
/// thus save you an `unwrap()` call.
|
||||||
pub fn new(qname: rxml::QName, attrs: rxml::AttrMap) -> Self {
|
pub fn new(qname: rxml::QName, attrs: rxml::AttrMap) -> Self {
|
||||||
let mut prefixes = SimpleNamespaces::new();
|
|
||||||
let mut builder = Element::builder(qname.1, qname.0);
|
let mut builder = Element::builder(qname.1, qname.0);
|
||||||
for ((namespace, name), value) in attrs.into_iter() {
|
for ((namespace, name), value) in attrs.into_iter() {
|
||||||
if namespace.is_none() {
|
builder = builder.attr_ns(namespace, name, value);
|
||||||
builder = builder.attr(name, value);
|
|
||||||
} else {
|
|
||||||
let (is_new, prefix) = prefixes.declare_with_auto_prefix(namespace.clone());
|
|
||||||
let name = prefix.with_suffix(&name);
|
|
||||||
if is_new {
|
|
||||||
builder = builder
|
|
||||||
.prefix(
|
|
||||||
Some(prefix.as_str().to_owned()),
|
|
||||||
namespace.as_str().to_owned(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
builder = builder.attr(name, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let element = builder.build();
|
let element = builder.build();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue