-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Common): introduce an XML driver
- Loading branch information
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ const DocSaveload = [ | |
"Tiff", | ||
"Webp", | ||
"XLSX", | ||
"XML", | ||
"Zip", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module XMLExt | ||
|
||
using XML | ||
import DataToolkitCommon: _read_xml, _write_xml | ||
|
||
function _read_xml(from::IO, as::Union{Type{XML.Node}, Type{XML.LazyNode}}) | ||
read(from, as) | ||
end | ||
|
||
function _write_xml(dest::IO, data::XML.Node) | ||
write(dest, data) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function _read_xml end # Implemented in `../../../ext/XMLExt.jl` | ||
function _write_xml end # Implemented in `../../../ext/XMLExt.jl` | ||
|
||
function load(loader::DataLoader{:xml}, from::IO, as::Type) | ||
@require XML | ||
QualifiedType(as) ∈ (QualifiedType(:XML, :Node), QualifiedType(:XML, :LazyNode)) || return | ||
invokelatest(_read_xml, from, as) | ||
end | ||
|
||
supportedtypes(::Type{DataLoader{:xml}}) = | ||
[QualifiedType(:XML, :LazyNode), QualifiedType(:XML, :Node)] | ||
|
||
function save(writer::DataWriter{:xml}, dest::IO, data) | ||
@require XML | ||
QualifiedType(typeof(data)) == QualifiedType(:XML, :Node) || return | ||
invokelatest(_write_xml, dest, data) | ||
end | ||
|
||
function createauto(::Type{DataLoader{:xml}}, source::String) | ||
!isnothing(match(r"\.xml$"i, source)) | ||
end | ||
|
||
const XML_DOC = md""" | ||
Load and write XML data. | ||
# Input/output | ||
The `xml` driver expects data to be provided via an `IO` stream. | ||
This driver supports parsing to two data types: | ||
- `XML.LazyNode` | ||
- `XML.Node` | ||
# Required packages | ||
- `XML` | ||
# Usage examples | ||
```toml | ||
[[sample.loader]] | ||
driver = "xml" | ||
``` | ||
""" |