I was reading an interesting discussion yesterday on xquery-talk, replacing a node in in-memory XML.
How can one modify an XML structure through XQuery? In the future, the answer is definitely XQuery Update Facility. But the XQuery Update Facility is currently still work in progress, and not yet widely supported. What do we do today? Ryan Grimm wrote an XQuery library to update an in-memory XML structure. And it looks like the in-mem-update library is pretty functional complete, having the following functions.{data($uid)} 1001 60 1999-02-01
into doc("bids.xml")/bids [/cc]
Using the library we end up doing something as follows,[cc lang="xquery"]import module namespace mem = "http://xqdev.com/in-mem-update" at "in-mem-update.xqy"; let $uid := doc("users.xml")/users/user_tuple[name="Annabel Lee"]/userid return mem:node-insert-child( doc("bids.xml")/bids, {data($uid)}
1001
60
1999-02-01
)[/cc]Looks pretty similar, no? There is actually one fundamental difference. With the XQuery Update Facility, the bids.xml document is actually updated. The in-mem-update variant, doesn't update the bids.xml document, but rather returns a copy of the original document reflecting the change.
This shows one of the possible issues with the library. Each modification made to an XML structure results in a copy. Making a lot of changes to a single XML structure, or updating a huge XML structure might affect performance. Still, I believe the library is useful in a lot of common scenarios.
View all posts from Marc Van Cappellen on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites