Using XPath to edit an XML document

XPath has been very helpful to me querying extremely large and complex 
XML schemas (FGDC and Remote Sensing Metadata Templates FYI).  My 
question is, why stop at querying documents.  It would be very useful to 
create xPath functions that allow one to create new Elements.  For example:

Lets say we have an xml document like so:

<root>
   <employee id="1">
      <name first="Travex" last="Stevex" />
      <family marriage="single" />
   </employee>
</root>

If I were to get married, I would create an xPath query 
"/root/employee[@id='1']/family"

This would return the family element and I would set the marriage 
attribute to be "married".  Well, if a family element did not exists, 
then this query would not work.  Why not have a function to create a new 
one if it does not exist: 
"/root/employee[@id='1']/family[createIfNonExistant()]

Lets say we want to add a new employee, xPath:

"/root/employee[new()]" would return a newly created employee element.

IMHO, I think it would only take these two functions to have a sort of 
element creational standard.

-Trav

Received on Wednesday, 12 November 2003 19:13:01 UTC