<addresses>
<address city="New York" />
<address city="Tampa" />
<address city="Bethesda" />
</addresses>
Using the following Xpath and instruction:
Xpath: /addresses/address[2]
Instruction: Insert a new address element before (as a preceding-sibling)
the element selected with the above Xpath. In this case, it would read
"Insert a new address element between the 'Tampa' and 'Bethesda' address
elements.
The Problem:
The problem here is that using XMLSearch() with the supplied XPath will
return the <address city="Tampa" /> without reference to any of the other
sibling <address> elements.
What would you do to address this? So far, I have an idea, but it seems too
"hackish":
1) Cache the index of the last location step in the xpath (in this case, 2).
2) Remove the last location step of the Xpath, XMLSearch() again to return
address[2]'s parent (with siblings now in XmlChildren)
3) Add 1 to the cached index (2+1=3).
4) Create the new <address> element with XMLElemNew()
5) Use ArrayInsertAt() to add the element to the parent.XMLChildren array,
using 3 as the insert point.
Anyone see an easier way, perhaps by using the XMLChildPos() function?
Thanks in advance!
----------------------------------
Alex Sherwood
PHS Collection Agency
THE COLLECTORS
T: 301.215.4200
F: 301.664.6834
W: www.phs-net.com
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]