Inserting into XML tables at arbitrary points
Simone Bettini
simone at evectors.it
Wed Mar 20 02:39:06 PST 2002
At 15:04 -0800 19-03-2002, Bill Humphries wrote:
>On Tuesday, March 19, 2002, at 02:12 PM, Greg Pierce wrote:
>
>>Can I ask exactly what you're trying to accomplish with arbitrary insertion?
>>
>>It seems the correct approach to this is to edit the XML before
>>compiling it to a table.
>
>Who's doing the editing though, if it's a domain expert familiar
>with XML markup, then yes, the right thing to do is edit the text,
>check for well-formedness, validate against DTD or schema if
>necessary, then compile.
>
>However, my users' expect a visual editing interface, and would run
>screaming for Gilroy if I asked them to edit markup. They aren't
>programmers.
There is another point too, xml.compile and xml.decompile are quite
slow verbs when applied to huge docs and/or tables.
In our CMS, that heavily uses xml tables we use the second approach
and modify tables, but pay attention not to assign huge tables, as
it's another processor intensive task.
A better approach imho would be to shif all items in table down in place:
on insertAt(theTableAdr, theItemName, theItemValue, thePosition) {
local {
tAdr;
tPos;
tTableSize = sizeOf(theTableAdr^)};
for tPos = tTableSize downto thePosition {
local {
tAdr = @theTableAdr^[tPos];
tName = xml.convertToDisplayName(tAdr^);
tNewName =string.padWithZeros(tPos+1,5) +
"000\t" + tName};
theTableAdr^.[tNewName] = tAdr^;
delete(tAdr)};
local {
tNewName =string.padWithZeros(thePosition,5) +
"000\t" + theItemName};
theTableAdr^.[tNewName] = theItemValue}
(i didn't test this function, so be careful using it)
But be careful, would the tag of the table have any attributes, or
the tag contain data then you would have /atts at the beginning and
one or more /pcdata somewhere inside the table, shifting down all
items by one:
<test num='1'>
bye bye
<item>Hi</item>
<item>Hi2</item>
<item>Hi3</item>
bye2
</test>
generates a table like this:
>00001000 test
>/atts
>num 1
>00002000\t/pcdata bye bye
>00003000\titem Hi
>00004000\titem Hi2
>00005000\titem Hi3
>00006000\t/pcdata bye2
So if you want to use such approach be sure at least no pcdata will
be included in your tables, and if you need to have any atts modify
the above script to deal with /atts table presence (you just need to
verify wether a /atts object is defined in the table and in such a
case shift positions accordingly)
--
Simone
---------------------------------------------------------------
"The web was built with hypertext, not hypergraphics."
Jeffrey Zeldman
---------------------------------------------------------------
More information about the Frontier-Users
mailing list