# How to get correct formatting using EzXML?

**URL:** <https://discourse.julialang.org/t/how-to-get-correct-formatting-using-ezxml/66428>\
**Category:** General Usage\
**Tags:** question, package, xml\
**Created:** [August 15, 2021, 7:33am UTC](https://discourse.julialang.org/t/how-to-get-correct-formatting-using-ezxml/66428 "2021-08-15T07:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [August 15, 2021, 7:33am UTC](https://discourse.julialang.org/t/how-to-get-correct-formatting-using-ezxml/66428/1 "2021-08-15T07:33:44Z")

</div>

Hi!

I am using EzXML trying to make my own custom XML file through julia. I want something that looks like:

```julia
<?xml version="1.0" encoding="UTF-8" ?>
<case>
    <casedef>
        <constantsdef>            
            <gravity x="0" y="0" z="-9.81" comment="Gravitational acceleration" units_comment="m/s^2" />
            <rhop0 value="1000" comment="Reference density of the fluid" units_comment="kg/m^3" />
        </constantsdef>
    </casedef>
</case>

```

Then using EzXML and this following code (very coarse code just to get it to work):

```julia
using EzXML

doc = parsexml("""
<?xml version="1.0" encoding="UTF-8" ?>
<case>
</case>
""")

rd = root(doc)

constantsdef = addelement!(rd,"constantsdef")

gravity = addelement!(constantsdef,"gravity")

gx = AttributeNode("x","0")
gy = AttributeNode("y","0")
gz = AttributeNode("z","-9.81")

link!(gravity,gx)
link!(gravity,gy)
link!(gravity,gz)

comment=AttributeNode("comment","Gravitational acceleration") 
units_comment=AttributeNode("units_comment","m/s^2")

link!(gravity,comment)
link!(gravity,units_comment)

rhop0 = addelement!(constantsdef,"rhop0")

rhop0_value = AttributeNode("value","1000")

link!(rhop0,rhop0_value)

comment=AttributeNode("comment","Reference density of the fluid") 
units_comment=AttributeNode("units_comment","kg/m^3")

link!(rhop0,comment)
link!(rhop0,units_comment)

write("Test.xml",doc)

```

The end result is:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/2/e2406310bc88ee7b9357d2daf4eebbd45f52490b.png)

Which is the correct elements, but no type of indentation / new lines are being applied to make it humanreadable too. Could anyone help out?

Thanks, kind regards

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [August 26, 2022, 8:26pm UTC](https://discourse.julialang.org/t/how-to-get-correct-formatting-using-ezxml/66428/2 "2022-08-26T20:26:04Z")

</div>

Is there really no one who knows how to achieve this?

Kind regards

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [August 30, 2022, 8:32pm UTC](https://discourse.julialang.org/t/how-to-get-correct-formatting-using-ezxml/66428/3 "2022-08-30T20:32:58Z")

</div>

EzXML exports a function `prettyprint`, which can be combined with IO operations (similar too println, but not exact), which allows to print XML in a human readable format and saving it to text.

So if you are a poor soul needing to do this as I needed it, now you know 🙂

Kind regards
