diff --git a/src/interpreter.rs b/src/interpreter.rs index a2af08c..ac852c0 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -13,12 +13,13 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use crate::element::ScanElement; +use crate::element::{ScanElement, DEFAULT_NS, SCANSION_NS}; use crate::parsers::{parse_spec, Token}; use crate::types::{Action, Context, Entity, Spec}; use jid::Jid; use minidom::{Element, Error as MinidomError}; use rand::{thread_rng, Rng}; +use std::collections::BTreeMap; #[cfg_attr(test, derive(PartialEq))] #[derive(Debug)] @@ -82,16 +83,30 @@ pub fn read_actions(spec: Spec, context: &Context) -> Result()?; - inout.receives(ScanElement::new(elem).with_context(Some(&context))); + let prefixes: BTreeMap, String> = { + let mut tmp = BTreeMap::new(); + tmp.insert(None, String::from(DEFAULT_NS)); + tmp.insert(Some(String::from("scansion")), String::from(SCANSION_NS)); + tmp + }; + + let elem = Element::from_reader_with_prefixes(s.as_ref(), prefixes)?; + inout.receives(ScanElement::new(elem).apply_context(&context)); } Action::Send(name, s) => { let _ = context .get(&name) .expect(format!("Name '{}' not found in clients", name).as_str()); - let elem = s.parse::()?; - inout.sends(ScanElement::new(elem).with_context(Some(&context))); + let prefixes: BTreeMap, String> = { + let mut tmp = BTreeMap::new(); + tmp.insert(None, String::from(DEFAULT_NS)); + tmp.insert(Some(String::from("scansion")), String::from(SCANSION_NS)); + tmp + }; + + let elem = Element::from_reader_with_prefixes(s.as_ref(), prefixes)?; + inout.sends(ScanElement::new(elem).apply_context(&context)); } _ => (), }