/
xmlutilities.jl
49 lines (39 loc) · 1.14 KB
/
xmlutilities.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"TEI namespace"
teins = "http://www.tei-c.org/ns/1.0"
"""
$(SIGNATURES)
Serialize an `EzXML.Node` to an XML string.
If a node `n` was created by parsing an XML string,
the output of `ezxmlstring(n)` will be XML equivalent
to the source string.
"""
function ezxmlstring(n::EzXML.Node)
ibuff = IOBuffer()
print(ibuff, n)
String(take!(ibuff))
end
"""
$(SIGNATURES)
Construct a `CitablePassage` from an element with a citable value on `@n` attribute.
"""
function citeNAttr(n, docUrn::CtsUrn)::CitablePassage
try
nodeUrn = addpassage(docUrn,n["n"])
CitablePassage(nodeUrn, ezxmlstring(n))
catch e
throw(DomainError("No `n` attribute found for XML node with content $(n.content)"))
end
end
"""
$(SIGNATURES)
Construct a `CitablePassage` from an element with citable value on `@n` attribute.
"""
function citeNAttr(n, docUrn::CtsUrn, psg::AbstractString)::CitablePassage
try
nattr = n["n"]
nodeUrn = addpassage(docUrn,psg * "." * nattr)
CitablePassage(nodeUrn, ezxmlstring(n))
catch e
throw(DomainError("No `n` attribute found for XML node with content $(n.content)"))
end
end