# How to convert EzXML.Document file into a dictionary

**URL:** <https://discourse.julialang.org/t/how-to-convert-ezxml-document-file-into-a-dictionary/102550>\
**Category:** New to Julia\
**Created:** [August 7, 2023, 7:56am UTC](https://discourse.julialang.org/t/how-to-convert-ezxml-document-file-into-a-dictionary/102550 "2023-08-07T07:56:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chao/32/50725_2.png) [@Chao](https://discourse.julialang.org/u/Chao)\
**Post date:** [August 7, 2023, 7:56am UTC](https://discourse.julialang.org/t/how-to-convert-ezxml-document-file-into-a-dictionary/102550/1 "2023-08-07T07:56:02Z")

</div>

Hello I just start to use Julia for programming. I have a XML dataset and used the EzXML package to get the data. The data is an N-element Vector{EzXML.Node}. For each EzXML.Node, it looks like this:

```julia
<event time="30000.0" type="actstart" person="200000" link="10000" x="40000.400" y="50000.500" actType="other_600.0"/>

<event time="60000.0" type="actend" person="400000" link="20000" x="50000.400" y="70000.500" actType="other_600.0"/>
....

```

By using EzXML.Node.name, I get “time”, or “type”, or “person”…  
By using EzXML.Node.content, I get “30000.0”, or “actstart”, or “200000” …  
My goal is to get a dictionary of the XML file.  
The dictionary will look like this:  
Dict{String, Int64} with 2 entries:  
“time” =\> 30000.0, 60000.0, …  
“type” =\> “actstart”, “attend”, …  
“person” =\> 200000, 400000, …  
“link” =\> 10000, 20000, …  
“x” =\> 40000.400, 20000, …  
“y” =\> 40000.400, 20000, …  
“actType” = “other\_600.0”, “other\_600.0”, …

I try to use this to get the dictionary but end with only getting error.

```julia
s = (elements(root(testxml)))
for i in range(1, length(s)), j in range(1, length(attributes(s[i])))
	contact_type1 = Dict() 
        if (occursin("actstart", string(s[i])) || (occursin("actend", string(s[i]))) ) && !occursin("interaction\"", string(s[i]))  
            (attributes(s[i]))[j].name = push!(keys(contact_type1), keys(contact_type1))
            (attributes(s[i]))[j].content = push!(values(contact_type1) , values(contact_type1))
		return(contact_type1)
    end
end
contact_type1

```

Thank you for any help. I am also looking for some suggestions on courseS about Julia programming course.

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [August 7, 2023, 11:22am UTC](https://discourse.julialang.org/t/how-to-convert-ezxml-document-file-into-a-dictionary/102550/2 "2023-08-07T11:22:03Z")

</div>

Check out XMLDict.jl!
