Using ⎕XML to generate "fragments"
Posted: Tue May 21, 2013 12:12 pm
I recently had the opportunity to use ⎕XML to generate XML (rather than read it), and may have experienced first hand an issue that I believe I have heard others discuss in the past - that ⎕XML does not provide a convenient mechanism for easily assembling fragments of XML into a whole.
For example, if I have a sub-function to create the leaves of my XML, which returns something along the lines of:
<person><name>Jill</name></person></person><name>Jack</name></person>
... And then I have a top-level function that needs to insert this into an "envelope" along the lines of:
<database>
<title>My friends</title>
[persons go here]
</database>
... It is a little awkward to do the last step. I was wondering whether it would make sense to extend ⎕XML so that pre-formatted XML can be inserted, so I could construct the above as follows:
xml←1 3⍴0 'database'
xml⍪← 1 'title' 'My friends'
xml⍪← ¯2 '' '<person><name>Jill</name>.....</person>'
In this case, the negative level number is the flag which marks the row as containing pre-build XML, but that is just an idea.
We would be interested to hear from anyone who has used ⎕XML to construct non-trivial output files: Would this be helpful, or do you have other ideas for features that would make it easier to construct large XML files?
For example, if I have a sub-function to create the leaves of my XML, which returns something along the lines of:
<person><name>Jill</name></person></person><name>Jack</name></person>
... And then I have a top-level function that needs to insert this into an "envelope" along the lines of:
<database>
<title>My friends</title>
[persons go here]
</database>
... It is a little awkward to do the last step. I was wondering whether it would make sense to extend ⎕XML so that pre-formatted XML can be inserted, so I could construct the above as follows:
xml←1 3⍴0 'database'
xml⍪← 1 'title' 'My friends'
xml⍪← ¯2 '' '<person><name>Jill</name>.....</person>'
In this case, the negative level number is the flag which marks the row as containing pre-build XML, but that is just an idea.
We would be interested to hear from anyone who has used ⎕XML to construct non-trivial output files: Would this be helpful, or do you have other ideas for features that would make it easier to construct large XML files?