How to append to an existing XML

deantangNYP

Active Member
Licensed User
Longtime User
HI Erel, created an XML using XML builder as follow

Dim x As XMLBuilder
x = x.create("Data")
x = x.element("Field") _
.element("id").text("01") _
.up() _
.element("job_no").text("A001")

Dim props As Map
props.Initialize
props.Put("indent", "yes")
File.WriteString(File.DirRootExternal, "create.xml", x.asString2((props))

How can i append XML? Please advise.

Expected XML OUTCOME......
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Field>
<id>01</id>
<job_no>A001</job_no>
</Field>
</Data>
<Data>
<Field>
<id>02</id>
<job_no>A002</job_no>
</Field>
</Data>
<Data>
<Field>
<id>03</id>
<job_no>A003</job_no>
</Field>
</Data>
 
Last edited:

deantangNYP

Active Member
Licensed User
Longtime User
Hi Erel, does it mean i need to Parse the existing XML data,then append with the New XML data to recreate a new XML file?

is there an existing example in the forum? Thanks.
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
hi Erel, one more question.. Thanks
I am trying to understand the usage of "create" and "element" before exploring parsing.
Is the code correct?

B4X:
Dim x As XMLBuilder
x = x.create("Data")
x = x.element("Field") _
     .element("id").text("01") _
     .up() _
     .element("job_no").text("A001") _
     .create("Data")  _
     .element("Field") _
     .element("id").text("02") _
     .up() _
     .element("job_no").text("A002")

Expected XML OUTCOME......
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Field>
<id>01</id>
<job_no>A001</job_no>
</Field>
</Data>
<Data>
<Field>
<id>02</id>
<job_no>A002</job_no>
</Field>
</Data>
 
Last edited:
Upvote 0
Top