RE: Retrieving parts of a document

"Kay, Michael" <[email protected]> Wed, 21 Jan 2004 16:33:48 +0100
Newsgroups gmane.text.xml.xpath.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.

------_=_NextPart_001_01C3E033.F6B898B5
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

The XPath type system does not have "tree" as a type of object, so an
XPath expression cannot retrieve a tree as such. Instead, when you are
interested in getting a tree, you select the node that is the root of
that tree. It's then up to the application to access the subtree below
this node in whatever way it wants, either using XPath navigation or
using the native data model accessors.
=20
Michael Kay

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kirmse, Daniel
Sent: 21 January 2004 09:02
To: [email protected]
Subject: Retrieving parts of a document



Hi,

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

Suppose this document:

<?xml version=3D"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() =
=3D
"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_01C3E033.F6B898B5
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Message</TITLE>

<META content=3D"MSHTML 6.00.2800.1276" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D834532115-21012004><FONT face=3DArial color=3D#0000ff =
size=3D2>The=20
XPath type system does not have "tree" as a type of object, so an XPath=20
expression cannot retrieve a tree as such. Instead, when you are =
interested in=20
getting a tree, you select the node that is the root of that tree. It's =
then up=20
to the application to access the subtree below this node in whatever way =
it=20
wants, either using XPath navigation or using the native data model=20
accessors.</FONT></SPAN></DIV>
<DIV><SPAN class=3D834532115-21012004><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D834532115-21012004><FONT face=3DArial color=3D#0000ff =

size=3D2>Michael Kay</FONT></SPAN></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid; MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr =
align=3Dleft><FONT=20
  face=3DTahoma size=3D2>-----Original Message-----<BR><B>From:</B>=20
  [email protected] =
[mailto:[email protected]]=20
  <B>On Behalf Of </B>Kirmse, Daniel<BR><B>Sent:</B> 21 January 2004=20
  09:02<BR><B>To:</B> [email protected]<BR><B>Subject:</B> =
Retrieving=20
  parts of a document<BR><BR></FONT></DIV>
  <P align=3Dleft><FONT face=3DArial size=3D2>Hi,</FONT></P>
  <P align=3Dleft><FONT face=3DArial size=3D2>is there a way to retrieve =
a part of a=20
  document as XML?</FONT></P>
  <P align=3Dleft><FONT face=3DArial size=3D2>Suppose this =
document:</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&lt;?xml=20
  version=3D"1.0"?&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&lt;!DOCTYPE =
chapter PUBLIC=20
  "-//X-HIVE/Generated Public ID 101//EN" "dtd/books.dtd"&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&lt;chapter&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp; =
&lt;title&gt;Data=20
  Model&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;=20
&lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;title&gt;Syntax For Data Model&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;=20
  &lt;/section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;=20
&lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;title&gt;XML&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;title&gt;Basic Syntax&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;/section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;title&gt;XML and Semistructured Data&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;</FONT> <FONT=20
  face=3D"Courier New" size=3D2>&lt;/section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;=20
  &lt;/section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&lt;/chapter&gt;</FONT></P>
  <P align=3Dleft><FONT face=3DArial size=3D2>The result I have in mind =
is:</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;=20
&lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;title&gt;XML&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;title&gt;Basic Syntax&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;/section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =

  &lt;section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  &lt;title&gt;XML and Semistructured Data&lt;/title&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" =
size=3D2>&nbsp;&nbsp;&nbsp;</FONT> <FONT=20
  face=3D"Courier New" size=3D2>&lt;/section&gt;</FONT></P>
  <P align=3Dleft><FONT face=3D"Courier New" size=3D2>&nbsp;=20
  &lt;/section&gt;</FONT></P><BR>
  <P align=3Dleft><FONT face=3DArial size=3D2>By using a XPath =
expression like=20
  /chapter/section[child::title</FONT><FONT face=3DArial =
size=3D2>/text() =3D</FONT>=20
  <FONT face=3DArial size=3D2>"</FONT><FONT face=3DArial =
size=3D2>XML</FONT><FONT=20
  face=3DArial size=3D2>"</FONT><FONT face=3DArial size=3D2>] I would =
merely navigate to=20
  the context of node</FONT> <FONT face=3DArial size=3D2>"</FONT><FONT =
face=3DArial=20
  size=3D2>section</FONT><FONT face=3DArial size=3D2>"</FONT><FONT =
face=3DArial size=3D2>=20
  (Well maybe the phrasing is not right. I hope I made you understand my =

  intention).</FONT></P>
  <P align=3Dleft><FONT face=3DArial size=3D2>Do I have to use XQuery to =
accomplish=20
  that?</FONT> <FONT face=3DArial size=3D2>Well I think I could write a =
XQuery=20
  expression for that example that generates the</FONT> <FONT =
face=3DArial=20
  size=3D2>output. But w</FONT><FONT face=3DArial size=3D2>hat if I do =
not know the=20
  structure of the subtree/part of document to retrieve but only the =
structure=20
  of the root node of this subtree/part of document</FONT><FONT =
face=3DArial=20
  size=3D2>?</FONT></P><BR>
  <P align=3Dleft><FONT face=3DArial size=3D2>Thanks,</FONT></P>
  <P align=3Dleft><FONT face=3DArial size=3D2>Daniel</FONT></P>
  <P align=3Dleft><A name=3D_MailAutoSig></A></P>
  <P align=3Dleft></P></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C3E033.F6B898B5--