Retrieving parts of a document

"Kirmse, Daniel" <[email protected]> Wed, 21 Jan 2004 10:01:59 +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_01C3DFFD.3A77B730
Content-Type: text/plain

Hi,

is there a way to retrieve a part of a document as XML?

Suppose this document:

<?xml version="1.0"?>

<!DOCTYPE chapter PUBLIC "-//X-HIVE/Generated Public ID 101//EN" "dtd/books.dtd">
<chapter>
  <title>Data Model</title>
  <section>
    <title>Syntax For Data Model</title>
  </section>
  <section>
    <title>XML</title>
    <section>
      <title>Basic Syntax</title>
    </section>
    <section>
      <title>XML and Semistructured Data</title>
    </section>
  </section>
</chapter>

The result I have in mind is:

  <section>
    <title>XML</title>
    <section>
      <title>Basic Syntax</title>
    </section>
    <section>
      <title>XML and Semistructured Data</title>
    </section>
  </section>


By using a XPath expression like /chapter/section[child::title/text() = "XML"] I would merely navigate to the context of node "section" (Well maybe the phrasing is not right. I hope I made you understand my intention).

Do I have to use XQuery to accomplish that? Well I think I could write a XQuery expression for that example that generates the output. But what if I do not know the structure of the subtree/part of document to retrieve but only the structure of the root node of this subtree/part of document?


Thanks,
Daniel



------_=_NextPart_001_01C3DFFD.3A77B730
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.2657.73">
<TITLE>Retrieving parts of a document</TITLE>
</HEAD>
<BODY>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">Hi,</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">is there a way to =
retrieve a part of a document as XML?</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">Suppose this =
document:</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&lt;?xml =
version=3D&quot;1.0&quot;?&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&lt;!DOCTYPE =
chapter PUBLIC &quot;-//X-HIVE/Generated Public ID 101//EN&quot; =
&quot;dtd/books.dtd&quot;&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&lt;chapter&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;title&gt;Data Model&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;title&gt;Syntax For Data Model&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;/section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;title&gt;XML&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;Basic =
Syntax&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;/section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;XML and Semistructured =
Data&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&nbsp;&nbsp;&nbsp;</FONT> <FONT SIZE=3D2 FACE=3D"Courier =
New">&lt;/section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;/section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&lt;/chapter&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">The result I have in mind =
is:</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;title&gt;XML&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;Basic =
Syntax&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;/section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; =
&lt;section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;title&gt;XML and Semistructured =
Data&lt;/title&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New">&nbsp;&nbsp;&nbsp;</FONT> <FONT SIZE=3D2 FACE=3D"Courier =
New">&lt;/section&gt;</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; =
&lt;/section&gt;</FONT></P>
<BR>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">By using a XPath =
expression like /chapter/section[child::title</FONT><FONT SIZE=3D2 =
FACE=3D"Arial">/text() =3D</FONT> <FONT SIZE=3D2 =
FACE=3D"Arial">"</FONT><FONT SIZE=3D2 FACE=3D"Arial">XML</FONT><FONT =
SIZE=3D2 FACE=3D"Arial">"</FONT><FONT SIZE=3D2 FACE=3D"Arial">] I would =
merely navigate to the context of node</FONT> <FONT SIZE=3D2 =
FACE=3D"Arial">"</FONT><FONT SIZE=3D2 =
FACE=3D"Arial">section</FONT><FONT SIZE=3D2 =
FACE=3D"Arial">"</FONT><FONT SIZE=3D2 FACE=3D"Arial"> (Well maybe the =
phrasing is not right. I hope I made you understand my =
intention).</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">Do I have to use XQuery =
to accomplish that?</FONT> <FONT SIZE=3D2 FACE=3D"Arial">Well I think I =
could write a XQuery expression for that example that generates =
the</FONT> <FONT SIZE=3D2 FACE=3D"Arial">output. But w</FONT><FONT =
SIZE=3D2 FACE=3D"Arial">hat if I do not know the structure of the =
subtree/part of document to retrieve but only the structure of the root =
node of this subtree/part of document</FONT><FONT SIZE=3D2 =
FACE=3D"Arial">?</FONT></P>
<BR>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">Thanks,</FONT></P>

<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Arial">Daniel</FONT></P>

<P ALIGN=3DLEFT><A NAME=3D"_MailAutoSig"></A></P>

<P ALIGN=3DLEFT></P>

</BODY>
</HTML>
------_=_NextPart_001_01C3DFFD.3A77B730--