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"><?xml =
version=3D"1.0"?></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"><!DOCTYPE =
chapter PUBLIC "-//X-HIVE/Generated Public ID 101//EN" =
"dtd/books.dtd"></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"><chapter></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<title>Data Model</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<title>Syntax For Data Model</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
</section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<title>XML</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"> <title>Basic =
Syntax</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
</section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"> <title>XML and Semistructured =
Data</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"> </FONT> <FONT SIZE=3D2 FACE=3D"Courier =
New"></section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
</section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"></chapter></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"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<title>XML</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"> <title>Basic =
Syntax</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
</section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
<section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"> <title>XML and Semistructured =
Data</title></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier =
New"> </FONT> <FONT SIZE=3D2 FACE=3D"Courier =
New"></section></FONT></P>
<P ALIGN=3DLEFT><FONT SIZE=3D2 FACE=3D"Courier New"> =
</section></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--