Skip to content

Commit df9d451

Browse files
committed
update README with examples
1 parent 8a5ea74 commit df9d451

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,58 @@ CLI tool for converting XML to RDF
33

44
This Rust-based tool converts XML data into RDF format, utilizing the `oxrdf` crate for RDF graph handling and `xml-rs` for efficient XML parsing. Generated triples can either be added to an `oxrdf::Graph` or written directly to file.
55

6+
## Using the xml2rdf CLI
7+
8+
This library includes a CLI utility for parsing XML and generating N-Triple RDF using the `convert` subcommand. The binary can be built using `cargo build`.
9+
10+
```bash
11+
$ xml2rdf convert --help
12+
Convert XML to RDF format.
13+
14+
The `convert` command parses a XML file, converts it to RDF triples using `xml-rs` for parsing and `oxrdf` to construct the graph, and saves the output.
15+
16+
Usage: xml2rdf convert [OPTIONS]
17+
18+
Options:
19+
-n, --namespace <NAMESPACE>
20+
Namespace for RDF graph generation.
21+
22+
A custom namespace to prefix RDF resources created from XML keys and values.
23+
24+
[default: https://decisym.ai/xml2rdf/data]
25+
26+
-x, --xml <XML>...
27+
Path to input XML file(s).
28+
29+
Provide the path to one or more XML files that will be parsed and converted.
30+
31+
-o, --output-file <OUTPUT_FILE>
32+
Path to output file.
33+
34+
Optional: Specify the path to save the generated RDF data. If not provided, data will be written to stdout
35+
36+
-h, --help
37+
Print help (see a summary with '-h')
38+
```
39+
40+
## Using the convert library
41+
42+
The conversion functionality can also be called directly in Rust. The library supports writing results to a file or building an in-memory `oxrdf::Graph`.
43+
44+
```rust
45+
use xml2rdf::convert::parse_xml;
46+
use xml2rdf::writer;
47+
use oxrdf::Graph;
48+
49+
// capture conversion results to file
50+
let mut w = writer::FileWriter::to_file("output.nt".to_string()).unwrap();
51+
parse_xml(vec!["data.xml".to_string()], &mut w, "https://decisym.ai/xml2rdf/data");
52+
53+
// capture conversion results to an oxrdf::Graph
54+
let mut g = Graph::new();
55+
let mut w = writer::GraphWriter::new(&mut g);
56+
parse_xml(vec!["data.xml".to_string()], &mut w, "https://decisym.ai/xml2rdf/data");
57+
```
58+
659
## License
760
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)