XML/DOM serialization: Difference between revisions

Line 627:
 
# create & attach a root node
xroot = create_root(xdoc, "Statesroot")
 
# create the first child
xs1 = new_child(xroot, "Stateelement")
 
# add the inner content
add_text(xs1, "Massachusettssome text here")
 
println(xdoc)
# set attribute
set_attribute(xs1, "tag", "MA")
 
# likewise for the second child
xs2 = new_child(xroot, "State")
add_text(xs2, "Illinois")
# set multiple attributes using a dict
set_attributes(xs2, Dict("tag"=>"IL", "cap"=>"Springfield"))
 
# now, the third child
xs3 = new_child(xroot, "State")
add_text(xs3, "California")
# set attributes using keyword arguments
set_attributes(xs3; tag="CA", cap="Sacramento")
 
println(xdoc)
</lang>{{output}}<pre>
<?xml version="1.0" encoding="utf-8"?>
<Statesroot>
<element>some text here</element>
<State tag="MA">Massachusetts</State>
</root>
<State tag="IL" cap="Springfield">Illinois</State>
<State tag="CA" cap="Sacramento">California</State>
</States>
</pre>
 
 
=={{header|Kotlin}}==
4,103

edits