use xmltree::Element; struct Options { ignoreProperties: bool, } #[test] fn main() { let data = r#" AAAL0G5vbmUCAAAAbW50clJHQiBYWVogB9QABwAVABMACwAhYWNzcAAAAAABAAAASUVDIHNSR0IAAAABAAAAAAAAAAAAAPbWAAEAAAAA0y1IUCAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQZGVzYwAAAUQAAAB0YlhZWgAAAbgAAAAUYlRSQwAAAcwAAAgMZG1kZAAACdgAAACIZ1hZWgAACmAAAAAUZ1RSQwAAAcwAAAgMbHVtaQAACnQAAAAUbWVhcwAACogAAAAkYmtwdAAACqwAAAAUclhZWgAACsAAAAAUclRSQwAAAcwAAAgMdGVjaAAACtQAAAAMdnVlZAAACuAAAACHd3RwdAAAC2gAAAAUY3BydAAAC3wAAAAoY2hhZAAAC6QAAAAsZGVzYwAAAAAAAAASc1JHQiBJRUM2MTk2Ni0yLjEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABYWVogAAAAAAAAJKAAAA+EAAC2z2N1cnYAAAAAAAAEAAAAAAUACgAPABQAGQAeACMAKAAtADIANwA7AEAARQBKAE8AVABZAF4AYwBoAG0AcgB3AHwAgQCGAIsAkACVAJoAnwCkAKkArgCyALcAvADBAMYAywDQANUA2wDgAOUA6wDwAPYA+wEBAQcBDQETARkBHwElASsBMgE4AT4BRQFMAVIBWQFgAWcBbgF1AXwBgwGLAZIBmgGhAakBsQG5AcEByQHRAdkB4QHpAfIB+gIDAgwCFAIdAiYCLwI4AkECSwJUAl0CZwJxAnoChAKOApgCogKsArYCwQLLAtUC4ALrAvUDAAMLAxYDIQMtAzgDQwNPA1oDZgNyA34DigOWA6IDrgO6A8cD0wPgA+wD+QQGBBMEIAQtBDsESARVBGMEcQR+BIwEmgSoBLYExATTBOEE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hzeot8p36/gNuC94UThzOJT4tvjY+Pr5HPk/OWE5g3mlucf56noMui86Ubp0Opb6uXrcOv77IbtEe2c7ijutO9A78zwWPDl8XLx//KM8xnzp/Q09ML1UPXe9m32+/eK+Bn4qPk4+cf6V/rn+3f8B/yY/Sn9uv5L/tz/bf//ZGVzYwAAAAAAAAAuSUVDIDYxOTY2LTItMSBEZWZhdWx0IFJHQiBDb2xvdXIgU3BhY2UgLSBzUkdCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAAAAAAFAAAAAAAABtZWFzAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJYWVogAAAAAAAAAxYAAAMzAAACpFhZWiAAAAAAAABvogAAOPUAAAOQc2lnIAAAAABDUlQgZGVzYwAAAAAAAAAtUmVmZXJlbmNlIFZpZXdpbmcgQ29uZGl0aW9uIGluIElFQyA2MTk2Ni0yLTEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAAD21gABAAAAANMtdGV4dAAAAABDb3B5cmlnaHQgSGV3bGV0dCBQYWNrYXJkLCAyMDA0AHNmMzIAAAAAAAEMRAAABd////MmAAAHlAAA/Y////uh///9ogAAA9sAAMB1 <?xml version="1.0" encoding="UTF-8"?><ProcessingHistory version="1.0"><instance class="Crop" enabled="true"><time start="2022-07-19T00:58:26.499Z" span="0.0019383"/><parameter id="leftMargin" value="0"/><parameter id="topMargin" value="0"/><parameter id="rightMargin" value="0"/><parameter id="bottomMargin" value="0"/><parameter id="mode" value="AbsolutePixels"/><parameter id="xResolution" value="72.000"/><parameter id="yResolution" value="72.000"/><parameter id="metric" value="false"/><parameter id="forceResolution" value="false"/><parameter id="red" value="0.000000"/><parameter id="green" value="0.000000"/><parameter id="blue" value="0.000000"/><parameter id="alpha" value="1.000000"/><parameter id="noGUIMessages" value="false"/></instance><instance class="Crop" enabled="true"><time start="2022-07-19T00:58:56.431Z" span="0.0254347"/><parameter id="leftMargin" value="-1479"/><parameter id="topMargin" value="-1479"/><parameter id="rightMargin" value="-1479"/><parameter id="bottomMargin" value="-1479"/><parameter id="mode" value="AbsolutePixels"/><parameter id="xResolution" value="72.000"/><parameter id="yResolution" value="72.000"/><parameter id="metric" value="false"/><parameter id="forceResolution" value="false"/><parameter id="red" value="0.000000"/><parameter id="green" value="0.000000"/><parameter id="blue" value="0.000000"/><parameter id="alpha" value="1.000000"/><parameter id="noGUIMessages" value="false"/></instance></ProcessingHistory> 2022-07-19T00:59:25Z PixInsight 1.8.8-12 XISF module version 1.0.13 Windows "#; let m_xisfOptions = Options { ignoreProperties: false, }; let root = Element::parse(data.as_bytes()).unwrap(); if root.name != "xisf" { panic!("Expected root element=xisf, instead found: {}", root.name); } let v = root.attributes.get("version"); match v { Some(x) => { if x != "1.0" { panic!("Expected XISF version: 1.0, instead found: {x}"); } } None => { panic!("Missing XISF version attribute"); } } for n in root.children { let e = n.as_element(); if e.is_none() { println!("Ignoring unexpected XML root child node of type: {n:#?}"); continue; } let e = e.unwrap(); if e.name == "Image" { println!("Found {:#?}", e.name); } else if e.name == "Property" { if !m_xisfOptions.ignoreProperties { println!("Found property: {} and not ignoring", e.name); todo!(); } } else if e.name == "Metadata" { println!("Found {:#?}", e.name); /* * The Metadata element contains a sequence of property child * elements. All of these properties are internal, i.e. they * are in the XISF namespace. */ for cn in e.children.iter() { let ce = cn.as_element(); if ce.is_none() { println!("Ignoring unexpected Meta child node of type: {cn:#?}"); continue; } let ce = ce.unwrap(); if ce.name == "Property" { println!("Found metadata property and not ignoring"); println!("{ce:#?}"); // todo!(); } else { println!("Skipping unknown metadata element: {}", ce.name); } } } else { println!("Skipping unknown element: {}", e.name); } } }