2019-11-05 11:03:23 +02:00
|
|
|
use super::XMLBuilder;
|
2019-11-06 07:55:14 +02:00
|
|
|
use super::XmlEvent;
|
2024-11-05 04:22:32 +02:00
|
|
|
use std::io::Write;
|
2019-11-05 11:03:23 +02:00
|
|
|
|
2024-11-05 04:22:32 +02:00
|
|
|
impl<W: Write> XMLBuilder<W> {
|
2019-11-05 11:03:23 +02:00
|
|
|
// Build RelationShips element
|
|
|
|
// i.e. <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
2020-01-24 10:57:14 +02:00
|
|
|
open!(open_relationships, "Relationships", "xmlns");
|
2019-11-05 11:03:23 +02:00
|
|
|
|
|
|
|
// Build Relationship
|
2020-01-24 10:57:14 +02:00
|
|
|
closed!(relationship, "Relationship", "Id", "Type", "Target");
|
2022-07-06 04:47:15 +03:00
|
|
|
closed!(
|
|
|
|
relationship_with_mode,
|
|
|
|
"Relationship",
|
|
|
|
"Id",
|
|
|
|
"Type",
|
|
|
|
"Target",
|
|
|
|
"TargetMode"
|
|
|
|
);
|
2019-11-05 11:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2024-11-05 04:22:32 +02:00
|
|
|
use super::*;
|
2019-11-05 11:03:23 +02:00
|
|
|
use std::str;
|
2024-11-05 04:22:32 +02:00
|
|
|
use xml::writer::Result;
|
2019-11-05 11:03:23 +02:00
|
|
|
|
|
|
|
#[test]
|
2024-11-05 04:22:32 +02:00
|
|
|
fn test_open_relationships() -> Result<()> {
|
|
|
|
let b = XMLBuilder::new(Vec::new());
|
2019-11-05 11:03:23 +02:00
|
|
|
let r = b
|
2024-11-05 04:22:32 +02:00
|
|
|
.open_relationships("http://example")?
|
|
|
|
.plain_text("child")?
|
|
|
|
.close()?
|
|
|
|
.into_inner()?
|
|
|
|
.into_inner();
|
2019-11-05 11:03:23 +02:00
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&r).unwrap(),
|
|
|
|
r#"<Relationships xmlns="http://example">child</Relationships>"#
|
|
|
|
);
|
2024-11-05 04:22:32 +02:00
|
|
|
Ok(())
|
2019-11-05 11:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-11-05 04:22:32 +02:00
|
|
|
fn test_relationship() -> Result<()> {
|
|
|
|
let b = XMLBuilder::new(Vec::new());
|
|
|
|
let r = b
|
|
|
|
.relationship("rId1", "http://example", "core.xml")?
|
|
|
|
.into_inner()?
|
|
|
|
.into_inner();
|
2019-11-05 11:03:23 +02:00
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&r).unwrap(),
|
|
|
|
r#"<Relationship Id="rId1" Type="http://example" Target="core.xml" />"#
|
|
|
|
);
|
2024-11-05 04:22:32 +02:00
|
|
|
Ok(())
|
2019-11-05 11:03:23 +02:00
|
|
|
}
|
|
|
|
}
|