Skip to content

Commit

Permalink
fix lang attr
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed May 9, 2024
1 parent 2f85b83 commit 48d736c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@latest
with:
version: '1.6.4'
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ODMXMLTools"
uuid = "2456a17b-6ca2-4f51-9342-f0287e829718"
authors = ["PharmCat <[email protected]>"]
version = "0.6.3"
version = "0.7.0"

[deps]

Expand All @@ -17,7 +17,7 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
AbstractTrees = "0.3, 0.4"
CategoricalArrays = "0.10"
DataFrames = "1"
EzXML = "1.1"
EzXML = "1.1, 1.2"
julia = "1"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion src/ODMXMLTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ module ODMXMLTools
:UserType
:Value
:Version
:lang
Symbol("xml:lang")
:xmlns])

const ITEMDATATYPE = Set([:ItemDataAny
Expand Down
4 changes: 2 additions & 2 deletions src/nodeinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const NODEINFO = Dict{Symbol, NodeInfo}(
),
:TranslatedText => NodeInfo(:TranslatedText,
[:Decode, :ErrorMessage, :Question, :Symbol, :Description],
Tuple{Symbol, Symbol, Symbol}[(:lang, :?, :languageTag)],
Tuple{Symbol, Symbol, Symbol}[(Symbol("xml:lang"), :?, :languageTag)],
"text"
),
:MetaDataVersion => NodeInfo(:MetaDataVersion,
Expand Down Expand Up @@ -278,7 +278,7 @@ const NODEINFO = Dict{Symbol, NodeInfo}(
),
:Presentation => NodeInfo(:Presentation,
:MetaDataVersion,
[(:OID, :!, :oid), (:lang, :?, :languageTag)],
[(:OID, :!, :oid), (Symbol("xml:lang"), :?, :languageTag)],
"text"
),
:ConditionDef => NodeInfo(:ConditionDef,
Expand Down
29 changes: 17 additions & 12 deletions src/odmxml.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,20 @@ function makenode(str, attr)
return ODMNode(Symbol(str), attr)
end
=#
function attributes_dict(n)
function attributes_dict(n, ns)
d = Dict{Symbol, String}()
for i in eachattribute(n)
d[Symbol(i.name)] = i.content
end
attributes_dict!(d, root, n)
d
end
function attributes_dict!(d, n)
for i in eachattribute(n)
d[Symbol(i.name)] = i.content
function attributes_dict!(d, ns, n)
for i in EzXML.attributes(n)
if EzXML.hasnamespace(i)
pref = ns[EzXML.namespace(i)]
k = Symbol(string(pref)*":"*i.name)
else
k = Symbol(i.name)
end
d[k] = i.content
end
d
end
Expand All @@ -109,11 +113,12 @@ function importxml(file::AbstractString)
nsv = namespaces(xodm)
if EzXML.hasnamespace(xodm)
nsv = namespaces(xodm)
push!(nsv, "xml" => "http://www.w3.org/XML/1998/namespace" )
else
nsv = ["" => ""]
nsv = ["xml" => "http://www.w3.org/XML/1998/namespace"]
end
ns = Dict([p[2] => Symbol(p[1]) for p in nsv]...)
odm = ODMRoot(attributes_dict(xodm), ns)
odm = ODMRoot(attributes_dict(xodm, ns), ns)
importxml_(odm, xodm, ns)
odm
end
Expand All @@ -125,7 +130,7 @@ function importxml_(parent, root, ns)
content = nothing
attr = Dict{Symbol, String}()
#if iselement(c)
attributes_dict!(attr, c)
attributes_dict!(attr, ns, c)
if !haselement(c)
tv = EzXML.eachnode(root)
for t in tv
Expand Down Expand Up @@ -1058,7 +1063,7 @@ function codelisttable(cd::AbstractODMNode; lang = "en")
text = content(first(tn))
if length(tn) > 1
for i = 2:length(tn)
if attribute(tn[i], :lang) == lang
if attribute(tn[i], Symbol("xml:lang")) == lang
text = content(tn[i])
break
end
Expand Down Expand Up @@ -1117,7 +1122,7 @@ function itemcodelisttable(cd::AbstractODMNode; lang = nothing)
text = content(first(tn))
if length(tn) > 1
for i = 2:length(tn)
if attribute(tn[i], :lang) == lang
if attribute(tn[i], Symbol("xml:lang")) == lang
text = content(tn[i])
break
end
Expand Down
6 changes: 5 additions & 1 deletion src/spss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ end
"""
spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name, source = :attr, lang = nothing)
SPSS command to set variable labels.
SPSS command to set variable labels:
```VARIABLE LABELS variable 'labels'.```
`variable` - varable names attribute, `OID` by default.
Expand All @@ -68,6 +70,8 @@ If `source` == `:Question` - try to get description from `TranslatedText` of `Qu
If `source` == `:Description` - try to get description from `TranslatedText` of `Description` element.
"""
function spss_form_variable_labels(mdb, form; variable = :OID, labels = :Name, source = :attr, lang = nothing)
df = itemformdefcontent_(mdb, form; optional = true)
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,14 @@ using EzXML
doc = EzXML.readxml(joinpath(dirname(@__FILE__), "test.xml"))
dtdn = EzXML.readdtd(joinpath(dirname(@__FILE__), "test-schema.dtd"))
EzXML.validate(doc, dtdn)
=#


#=
txt = """<?xml version="1.0" encoding="UTF-8"?>
<t1>
<t2 xml:name="Homo"></t2>
<t2 b:name="Homo"></t2>
</t1>"""
root(EzXML.parsexml(txt));
=#
14 changes: 8 additions & 6 deletions test/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,26 @@
<CodeList OID="CL_1" Name="Race codelist" DataType="integer" SASFormatName="CL_1">
<CodeListItem CodedValue="1">
<Decode>
<TranslatedText>Asian</TranslatedText>
<TranslatedText xml:lang = "en-US">Asian</TranslatedText>
<TranslatedText xml:lang = "ru">Азиатская</TranslatedText>
</Decode>
</CodeListItem>
<CodeListItem CodedValue="2">
<Decode>
<TranslatedText>Caucasian</TranslatedText>
<TranslatedText xml:lang = "en-US">Caucasian</TranslatedText>
<TranslatedText xml:lang = "ru">Европеоидная</TranslatedText>
</Decode>
</CodeListItem>
</CodeList>
<CodeList OID="CL_2" Name="Sex codelist" DataType="string" SASFormatName="CL_2">
<CodeListItem CodedValue="M">
<Decode>
<TranslatedText>Male</TranslatedText>
<TranslatedText xml:lang = "en-US">Male</TranslatedText>
</Decode>
</CodeListItem>
<CodeListItem CodedValue="F">
<Decode>
<TranslatedText>Female</TranslatedText>
<TranslatedText xml:lang = "en-US">Female</TranslatedText>
</Decode>
</CodeListItem>
</CodeList>
Expand All @@ -154,12 +156,12 @@
<CodeList OID="CL_2" Name="Sex codelist" DataType="integer" SASFormatName="CL_2">
<CodeListItem CodedValue="1">
<Decode>
<TranslatedText>Male</TranslatedText>
<TranslatedText xml:lang = "en-US">Male</TranslatedText>
</Decode>
</CodeListItem>
<CodeListItem CodedValue="2">
<Decode>
<TranslatedText>Female</TranslatedText>
<TranslatedText xml:lang = "en-US">Female</TranslatedText>
</Decode>
</CodeListItem>
</CodeList>
Expand Down

0 comments on commit 48d736c

Please sign in to comment.