From 1190dd9001a5c945f576064281b2cdcc6f82f5a1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 20 Apr 2017 21:03:02 +0100 Subject: [PATCH] disco: Add a serializer. --- src/disco.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/disco.rs b/src/disco.rs index afb1fa7..2a4ff64 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -106,6 +106,34 @@ pub fn parse_disco(root: &Element) -> Result { }); } +pub fn serialise_disco(disco: Disco) -> Element { + let mut root = Element::builder("query") + .ns(DISCO_INFO_NS) + .attr("node", disco.node) + .build(); + for identity in disco.identities { + let identity_element = Element::builder("identity") + .ns(DISCO_INFO_NS) + .attr("category", identity.category) + .attr("type", identity.type_) + .attr("xml:lang", identity.xml_lang) + .attr("name", identity.name) + .build(); + root.append_child(identity_element); + } + for feature in disco.features { + let feature_element = Element::builder("feature") + .ns(DISCO_INFO_NS) + .attr("var", feature.var) + .build(); + root.append_child(feature_element); + } + for _ in disco.extensions { + panic!("Not yet implemented!"); + } + root +} + #[cfg(test)] mod tests { use minidom::Element;