diff --git a/Cargo.lock b/Cargo.lock index 9d04b83..493ec46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,4 +3,14 @@ [[package]] name = "docx-core" version = "0.1.0" +dependencies = [ + "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] +[[package]] +name = "xml-rs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" diff --git a/docx-core/Cargo.toml b/docx-core/Cargo.toml index bfac336..95cfdd6 100644 --- a/docx-core/Cargo.toml +++ b/docx-core/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] \ No newline at end of file +[dependencies] +xml-rs = "0.8.0" \ No newline at end of file diff --git a/docx-core/examples/example.rs b/docx-core/examples/example.rs index 321cc34..9a850eb 100644 --- a/docx-core/examples/example.rs +++ b/docx-core/examples/example.rs @@ -1,5 +1,5 @@ extern crate docx_core; fn main() { - println!("{}", docx_core::add_one(1)); + docx_core::simple(); } \ No newline at end of file diff --git a/docx-core/fixtures/hello/[Content_Types].xml b/docx-core/fixtures/hello/[Content_Types].xml new file mode 100644 index 0000000..dc111cb --- /dev/null +++ b/docx-core/fixtures/hello/[Content_Types].xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello/_rels/.rels b/docx-core/fixtures/hello/_rels/.rels new file mode 100644 index 0000000..f0b72e7 --- /dev/null +++ b/docx-core/fixtures/hello/_rels/.rels @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello/docProps/app.xml b/docx-core/fixtures/hello/docProps/app.xml new file mode 100644 index 0000000..f819b8e --- /dev/null +++ b/docx-core/fixtures/hello/docProps/app.xml @@ -0,0 +1,2 @@ + +0LibreOffice/6.0.7.3$Linux_X86_64 LibreOffice_project/00m0$Build-311551 \ No newline at end of file diff --git a/docx-core/fixtures/hello/docProps/core.xml b/docx-core/fixtures/hello/docProps/core.xml new file mode 100644 index 0000000..aa2d79a --- /dev/null +++ b/docx-core/fixtures/hello/docProps/core.xml @@ -0,0 +1,2 @@ + +2019-09-13T19:32:17Zja-JP2019-09-13T19:32:34Z1 \ No newline at end of file diff --git a/docx-core/fixtures/hello/hello.docx b/docx-core/fixtures/hello/hello.docx new file mode 100644 index 0000000..a0c0223 Binary files /dev/null and b/docx-core/fixtures/hello/hello.docx differ diff --git a/docx-core/fixtures/hello/word/_rels/document.xml.rels b/docx-core/fixtures/hello/word/_rels/document.xml.rels new file mode 100644 index 0000000..6ac87fd --- /dev/null +++ b/docx-core/fixtures/hello/word/_rels/document.xml.rels @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello/word/document.xml b/docx-core/fixtures/hello/word/document.xml new file mode 100644 index 0000000..775c58a --- /dev/null +++ b/docx-core/fixtures/hello/word/document.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + Hello + + + + + + + + + + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello/word/fontTable.xml b/docx-core/fixtures/hello/word/fontTable.xml new file mode 100644 index 0000000..d7d5fd9 --- /dev/null +++ b/docx-core/fixtures/hello/word/fontTable.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello/word/settings.xml b/docx-core/fixtures/hello/word/settings.xml new file mode 100644 index 0000000..a516ac4 --- /dev/null +++ b/docx-core/fixtures/hello/word/settings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello/word/styles.xml b/docx-core/fixtures/hello/word/styles.xml new file mode 100644 index 0000000..d8d8049 --- /dev/null +++ b/docx-core/fixtures/hello/word/styles.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/[Content_Types].xml b/docx-core/fixtures/hello_world/[Content_Types].xml new file mode 100644 index 0000000..9c5c964 --- /dev/null +++ b/docx-core/fixtures/hello_world/[Content_Types].xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/_rels/.rels b/docx-core/fixtures/hello_world/_rels/.rels new file mode 100644 index 0000000..1399e4d --- /dev/null +++ b/docx-core/fixtures/hello_world/_rels/.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/docProps/app.xml b/docx-core/fixtures/hello_world/docProps/app.xml new file mode 100644 index 0000000..8993710 --- /dev/null +++ b/docx-core/fixtures/hello_world/docProps/app.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/docProps/core.xml b/docx-core/fixtures/hello_world/docProps/core.xml new file mode 100644 index 0000000..3f8b481 --- /dev/null +++ b/docx-core/fixtures/hello_world/docProps/core.xml @@ -0,0 +1 @@ +Un-namedUn-named12019-09-13T19:25:28Z2019-09-13T19:25:28Z \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/hello_world.docx b/docx-core/fixtures/hello_world/hello_world.docx new file mode 100644 index 0000000..9f37ec3 Binary files /dev/null and b/docx-core/fixtures/hello_world/hello_world.docx differ diff --git a/docx-core/fixtures/hello_world/word/_rels/document.xml.rels b/docx-core/fixtures/hello_world/word/_rels/document.xml.rels new file mode 100644 index 0000000..05a042b --- /dev/null +++ b/docx-core/fixtures/hello_world/word/_rels/document.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/_rels/footer1.xml.rels b/docx-core/fixtures/hello_world/word/_rels/footer1.xml.rels new file mode 100644 index 0000000..7b81324 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/_rels/footer1.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/_rels/header1.xml.rels b/docx-core/fixtures/hello_world/word/_rels/header1.xml.rels new file mode 100644 index 0000000..7b81324 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/_rels/header1.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/document.xml b/docx-core/fixtures/hello_world/word/document.xml new file mode 100644 index 0000000..9d20cc4 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/document.xml @@ -0,0 +1,44 @@ + + + + + + + + + Hello World + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/footer1.xml b/docx-core/fixtures/hello_world/word/footer1.xml new file mode 100644 index 0000000..05a9751 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/footer1.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/footnotes.xml b/docx-core/fixtures/hello_world/word/footnotes.xml new file mode 100644 index 0000000..edbd2f4 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/footnotes.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/header1.xml b/docx-core/fixtures/hello_world/word/header1.xml new file mode 100644 index 0000000..08805f3 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/header1.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/numbering.xml b/docx-core/fixtures/hello_world/word/numbering.xml new file mode 100644 index 0000000..0f46501 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/numbering.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/fixtures/hello_world/word/styles.xml b/docx-core/fixtures/hello_world/word/styles.xml new file mode 100644 index 0000000..c9a6343 --- /dev/null +++ b/docx-core/fixtures/hello_world/word/styles.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docx-core/src/lib.rs b/docx-core/src/lib.rs index 00ede4f..9aad3cf 100644 --- a/docx-core/src/lib.rs +++ b/docx-core/src/lib.rs @@ -1,4 +1,24 @@ +use std::fs::File; +use std::io::{self, Write}; -pub fn add_one(x: i32) -> i32 { - x + 1 +use xml::writer::{EmitterConfig, EventWriter, Result, XmlEvent}; + +pub fn simple() { + let mut file = File::create("./dist/output.xml").unwrap(); + let mut b = Vec::new(); + let mut w = EmitterConfig::new() + .write_document_declaration(false) + .create_writer(&mut b); + + w.write(XmlEvent::start_element("h:hello").ns("h", "urn:hello-world")) + .unwrap(); + w.write("hello world").unwrap(); + w.write(XmlEvent::end_element()).unwrap(); + + file.write_all(&b).unwrap(); + file.flush().unwrap(); + // assert_eq!( + // str::from_utf8(&b).unwrap(), + // r#"hello world"# + // ); }