RE: Using XPath to edit an XML document
"Kay, Michael" <[email protected]> Thu, 13 Nov 2003 16:05:26 +0100
| Newsgroups | gmane.text.xml.xpath.general |
|---|---|
| Message-ID | <[email protected]> |
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C3A9F7.91FAB9D0 Content-Type: text/plain XQuery extends XPath by allowing you to define functions and to create new elements in a result document (though not to modify the original source document). Is that what you're looking for? Michael Kay > -----Original Message----- > From: Travis Stevens [mailto:[email protected]] > Sent: 13 November 2003 00:13 > To: [email protected] > Subject: 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 > ------_=_NextPart_001_01C3A9F7.91FAB9D0 Content-Type: text/html Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version = 5.5.2653.12"> <TITLE>RE: Using XPath to edit an XML document</TITLE> </HEAD> <BODY> <P><FONT SIZE=3D2>XQuery extends XPath by allowing you to define = functions and to create new elements in a result document (though not = to modify the original source document). Is that what you're looking = for?</FONT></P> <P><FONT SIZE=3D2>Michael Kay</FONT> </P> <BR> <P><FONT SIZE=3D2>> -----Original Message-----</FONT> <BR><FONT SIZE=3D2>> From: Travis Stevens [<A = HREF=3D"mailto:[email protected]">mailto:[email protected]</= A>] </FONT> <BR><FONT SIZE=3D2>> Sent: 13 November 2003 00:13</FONT> <BR><FONT SIZE=3D2>> To: [email protected]</FONT> <BR><FONT SIZE=3D2>> Subject: Using XPath to edit an XML = document</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> XPath has been very helpful to me querying = extremely large </FONT> <BR><FONT SIZE=3D2>> and complex </FONT> <BR><FONT SIZE=3D2>> XML schemas (FGDC and Remote Sensing Metadata = Templates FYI). My </FONT> <BR><FONT SIZE=3D2>> question is, why stop at querying = documents. It would be </FONT> <BR><FONT SIZE=3D2>> very useful to </FONT> <BR><FONT SIZE=3D2>> create xPath functions that allow one to create = new Elements. </FONT> <BR><FONT SIZE=3D2>> For example:</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> Lets say we have an xml document like = so:</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> <root></FONT> <BR><FONT SIZE=3D2>> <employee = id=3D"1"></FONT> <BR><FONT SIZE=3D2>> <name = first=3D"Travex" last=3D"Stevex" /></FONT> <BR><FONT SIZE=3D2>> <family = marriage=3D"single" /></FONT> <BR><FONT SIZE=3D2>> </employee></FONT> <BR><FONT SIZE=3D2>> </root></FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> If I were to get married, I would create an = xPath query </FONT> <BR><FONT SIZE=3D2>> = "/root/employee[@id=3D'1']/family"</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> This would return the family element and I = would set the marriage </FONT> <BR><FONT SIZE=3D2>> attribute to be "married". = Well, if a family element did not exists, </FONT> <BR><FONT SIZE=3D2>> then this query would not work. Why not = have a function to </FONT> <BR><FONT SIZE=3D2>> create a new </FONT> <BR><FONT SIZE=3D2>> one if it does not exist: </FONT> <BR><FONT SIZE=3D2>> = "/root/employee[@id=3D'1']/family[createIfNonExistant()]</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> Lets say we want to add a new employee, = xPath:</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> "/root/employee[new()]" would return = a newly created employee element.</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> IMHO, I think it would only take these two = functions to have </FONT> <BR><FONT SIZE=3D2>> a sort of </FONT> <BR><FONT SIZE=3D2>> element creational standard.</FONT> <BR><FONT SIZE=3D2>> </FONT> <BR><FONT SIZE=3D2>> -Trav</FONT> <BR><FONT SIZE=3D2>> </FONT> </P> </BODY> </HTML> ------_=_NextPart_001_01C3A9F7.91FAB9D0--