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>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=3D2>&gt; From: Travis Stevens [<A =
HREF=3D"mailto:[email protected]">mailto:[email protected]</=
A>] </FONT>
<BR><FONT SIZE=3D2>&gt; Sent: 13 November 2003 00:13</FONT>
<BR><FONT SIZE=3D2>&gt; To: [email protected]</FONT>
<BR><FONT SIZE=3D2>&gt; Subject: Using XPath to edit an XML =
document</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; XPath has been very helpful to me querying =
extremely large </FONT>
<BR><FONT SIZE=3D2>&gt; and complex </FONT>
<BR><FONT SIZE=3D2>&gt; XML schemas (FGDC and Remote Sensing Metadata =
Templates FYI).&nbsp; My </FONT>
<BR><FONT SIZE=3D2>&gt; question is, why stop at querying =
documents.&nbsp; It would be </FONT>
<BR><FONT SIZE=3D2>&gt; very useful to </FONT>
<BR><FONT SIZE=3D2>&gt; create xPath functions that allow one to create =
new Elements. </FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp; For example:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Lets say we have an xml document like =
so:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; &lt;root&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp; &lt;employee =
id=3D&quot;1&quot;&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;name =
first=3D&quot;Travex&quot; last=3D&quot;Stevex&quot; /&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;family =
marriage=3D&quot;single&quot; /&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp; &lt;/employee&gt;</FONT>
<BR><FONT SIZE=3D2>&gt; &lt;/root&gt;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; If I were to get married, I would create an =
xPath query </FONT>
<BR><FONT SIZE=3D2>&gt; =
&quot;/root/employee[@id=3D'1']/family&quot;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; This would return the family element and I =
would set the marriage </FONT>
<BR><FONT SIZE=3D2>&gt; attribute to be &quot;married&quot;.&nbsp; =
Well, if a family element did not exists, </FONT>
<BR><FONT SIZE=3D2>&gt; then this query would not work.&nbsp; Why not =
have a function to </FONT>
<BR><FONT SIZE=3D2>&gt; create a new </FONT>
<BR><FONT SIZE=3D2>&gt; one if it does not exist: </FONT>
<BR><FONT SIZE=3D2>&gt; =
&quot;/root/employee[@id=3D'1']/family[createIfNonExistant()]</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Lets say we want to add a new employee, =
xPath:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; &quot;/root/employee[new()]&quot; would return =
a newly created employee element.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; IMHO, I think it would only take these two =
functions to have </FONT>
<BR><FONT SIZE=3D2>&gt; a sort of </FONT>
<BR><FONT SIZE=3D2>&gt; element creational standard.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; -Trav</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C3A9F7.91FAB9D0--