I need a help. how can i add content recursively to an xml file. i have a program which processes a file and send ‘line information’s. these line informations needs to be written to an XML file, like shown below. what i do now is I read each line info and then send it a fn which writes XML. I want to know if there is any way to Buffer the Document object and then keep keeping appending to that Document object when each new line comes.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <Rev_1.28>
- <OP type="SAM">
<SRC_LN_FROM>612612</SRC_LN_FROM>
<SRC_LN_TO>703703</SRC_LN_TO>
<NO_LINES>92</NO_LINES>
</OP>
- <OP type="MOV">
<SRC_LN_FROM>6122</SRC_LN_FROM>
<SRC_LN_TO>7033</SRC_LN_TO>
<NO_LINES>9</NO_LINES>
</OP>
</Rev_1.28>
You can use DOM parser to create use org.w3c.dom.Document object as shown here.
The data is stored in primary memory, so this approach is acceptable if the data to be written is relativley small.