XPathAPI not obeying XPath properly

Discussion in 'Java' started by Richard Bondi, Aug 25, 2004.

  1. Dear All,

    I'm having problems getting XPathAPI to work. What it is doing makes
    no sense to me; I hope someone explain what is going on!

    Given:
    ======
    1) The xml at the end of this post. (It is a stripped down version of
    an Open Office file, exported using a filter that consists simply of a
    xsl:copy-of in the root template.)
    2) The following xsl for XPathAPI:

    /office:document/office:body/text:p[1][@text:style-name='__ChapterTitle']
    | /office:document/office:body/text:p[1][@text:style-name='Heading 1']
    | /office:document/office:body/text:p[1][@text:style-name=/office:document/office:automatic-styles/style:style[@style:parent-style-name
    = '__ChapterTitle']/@style:name]
    | /office:document/office:body/text:p[1][@text:style-name=/office:document/office:automatic-styles/style:style[@style:parent-style-name
    = 'Heading 1']/@style:name]
    | /office:document/office:body/text:h[1][@text:style-name='Heading 1']
    | /office:document/office:body/text:h[1][@text:style-name=/office:document/office:automatic-styles/style:style[@style:parent-style-name
    = '__ChapterTitle']/@style:name]
    | /office:document/office:body/text:h[1][@text:style-name=/office:document/office:automatic-styles/style:style[@style:parent-style-name
    = 'Heading 1']/@style:name]

    The only part of this that actually returns a node is:
    /office:document/office:body/text:p[1][@text:style-name=/office:document/office:automatic-styles/style:style[@style:parent-style-name
    = '__ChapterTitle']/@style:name]

    The xsl works fine when used in a transformation in Java, and in Xml
    Spy.

    The problem:
    ===========

    XPathAPI appears to be stark staring bonkers. Here's the code:

    // My imports:
    import org.xml.sax.SAXException;
    import org.xml.sax.InputSource;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.apache.xpath.XPathAPI;

    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.dom.DOMSource;
    import java.io.IOException;
    import java.io.StringReader;
    import java.io.StringWriter;
    import java.io.File;

    // Load the xml from a file
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    File file = File("load the xml here, see bottom of this post for it");
    private Document _oodoc = factory.newDocumentBuilder().parse(file);
    factory = null;

    // Try to extract the paragraph specified by the above xsl; it is
    // the paragraph with the word "Introduction".

    String xsl = "... the xsl listed above under "Given" ...";
    Node node = null;

    // Here's what should work:
    // param1: the node to search from
    // param2: the xsl
    // param3: the node containing the definition of all
    // the namespaces; in this case, /office:document
    node = XPathAPI.selectSingleNode(_oodoc,
    xsl,
    _oodoc.getDocumentElement());

    // But node is null! Why?!

    // Try it with just the snippet of xsl that we know works
    // in this document
    xsl = "/office:document/office:body/text:p[1][@text:style-
    name=/office:document/office:automatic-styles/style:style[@style:parent-style
    name = '__ChapterTitle']/@style:name]";
    node = XPathAPI.selectSingleNode(_oodoc, xsl,
    _oodoc.getDocumentElement());

    // No, node is still null.

    // So try this to test:
    node = XPathAPI.selectSingleNode(_oodoc,
    "//office:document",
    _oodoc.getDocumentElement());
    // Nope, node is still null. What the...?!

    // Start flailing: try "/office:document": Nope, node is null.
    // In short-hand:

    // "/office:document" --> node is null
    node = XPathAPI.selectSingleNode(_oodoc,
    "/office:document",
    _oodoc.getDocumentElement());

    // "/document" --> node.getNodeName() == 'office:document'.
    // But why did that work? I didn't specify the namespace!
    node = XPathAPI.selectSingleNode(_oodoc,
    "/document",
    _oodoc.getDocumentElement());

    // "document" --> node.getNodeName() == 'office:document'.
    // But why did that work? I didn't specify the namespace!
    node = XPathAPI.selectSingleNode(_oodoc,
    "document",
    _oodoc.getDocumentElement());

    // "//document" --> node null. XPathAPI has totally lost it!
    // If "document" and "/document" work, "//document" should too!
    node = XPathAPI.selectSingleNode(_oodoc,
    "//document",
    _oodoc.getDocumentElement());

    // "*" --> node.getNodeName() == 'office:document'.
    // But why did that work? I didn't specify the namespace!
    node = XPathAPI.selectSingleNode(_oodoc,
    "*",
    _oodoc.getDocumentElement());

    // "//*" --> node.getNodeName() == 'office:document'.
    // So "//document" does not work, but "//*" does??!
    // XPathAPI is bananas.
    node = XPathAPI.selectSingleNode(_oodoc,
    "//*",
    _oodoc.getDocumentElement());

    --

    There are two variations I've tried which yield identical results:
    - repeat without the third parameter
    - repeat with selectNodeList instead of selectSingleNode.

    Note that I cannot transform as a work-around: the input documents are
    huge and therefore very slow.
    What I want to do is extract this one title, then later break up the
    document into manageable chunks
    for transforming.

    All I want is to grab a single node with XPathAPI.

    Stumped, stuck, and steamed,
    Richard Bondi

    Thanks much in advance!



    The xml:
    =======
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <office:document xmlns:eek:ffice="http://openoffice.org/2000/office"
    xmlns:style="http://openoffice.org/2000/style"
    xmlns:text="http://openoffice.org/2000/text"
    xmlns:table="http://openoffice.org/2000/table"
    xmlns:draw="http://openoffice.org/2000/drawing"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:meta="http://openoffice.org/2000/meta"
    xmlns:number="http://openoffice.org/2000/datastyle"
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns:chart="http://openoffice.org/2000/chart"
    xmlns:dr3d="http://openoffice.org/2000/dr3d"
    xmlns:math="http://www.w3.org/1998/Math/MathML"
    xmlns:form="http://openoffice.org/2000/form"
    xmlns:script="http://openoffice.org/2000/script"
    xmlns:config="http://openoffice.org/2001/config" office:class="text"
    office:version="1.0">
    <office:styles>
    <style:default-style style:family="graphics">
    <style:properties draw:start-line-spacing-horizontal="0.1114inch"
    draw:start-line-spacing-vertical="0.1114inch"
    draw:end-line-spacing-horizontal="0.1114inch"
    draw:end-line-spacing-vertical="0.1114inch"
    style:use-window-font-color="true" style:font-name="Times New Roman"
    fo:font-size="12pt" fo:language="en" fo:country="US"
    style:font-name-asian="Arial Unicode MS1" style:font-size-asian="12pt"
    style:language-asian="none" style:country-asian="none"
    style:font-name-complex="Tahoma" style:font-size-complex="12pt"
    style:language-complex="none" style:country-complex="none"
    style:text-autospace="ideograph-alpha" style:line-break="strict"
    style:writing-mode="lr-tb">
    <style:tab-stops/>
    </style:properties>
    </style:default-style>
    <style:default-style style:family="paragraph">
    <style:properties style:use-window-font-color="true"
    style:font-name="Times New Roman" fo:font-size="12pt" fo:language="en"
    fo:country="US" style:font-name-asian="Arial Unicode MS1"
    style:font-size-asian="12pt" style:language-asian="none"
    style:country-asian="none" style:font-name-complex="Tahoma"
    style:font-size-complex="12pt" style:language-complex="none"
    style:country-complex="none" fo:hyphenate="false"
    fo:hyphenation-remain-char-count="2"
    fo:hyphenation-push-char-count="2"
    fo:hyphenation-ladder-count="no-limit"
    style:text-autospace="ideograph-alpha"
    style:punctuation-wrap="hanging" style:line-break="strict"
    style:tab-stop-distance="0.5inch" style:writing-mode="page"/>
    </style:default-style>
    <style:style style:name="Standard" style:family="paragraph"
    style:class="text">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.0835inch" fo:margin-bottom="0.0835inch"
    style:use-window-font-color="true" style:font-name="Arial Unicode MS"
    fo:font-size="12pt" fo:language="en" fo:country="US"
    style:font-name-asian="Arial Unicode MS" style:font-size-asian="12pt"
    style:font-name-complex="Arial Unicode MS"
    style:font-size-complex="12pt" style:language-complex="ar"
    style:country-complex="SA" fo:eek:rphans="2" fo:widows="2"
    fo:text-indent="0.2inch" style:auto-text-indent="false"
    style:writing-mode="lr-tb"/>
    </style:style>
    <style:style style:name="Text body" style:family="paragraph"
    style:parent-style-name="Standard" style:class="text">
    <style:properties fo:margin-top="0inch"
    fo:margin-bottom="0.0835inch"/>
    </style:style>
    <style:style style:name="List" style:family="paragraph"
    style:parent-style-name="Text body" style:class="list">
    <style:properties style:font-name-complex="Tahoma1"/>
    </style:style>
    <style:style style:name="Caption" style:family="paragraph"
    style:parent-style-name="Standard" style:class="extra">
    <style:properties fo:margin-top="0.0835inch"
    fo:margin-bottom="0.0835inch" fo:font-size="10pt"
    fo:font-style="italic" style:font-size-asian="10pt"
    style:font-style-asian="italic" style:font-name-complex="Tahoma1"
    style:font-size-complex="10pt" style:font-style-complex="italic"
    text:number-lines="false" text:line-number="0"/>
    </style:style>
    <style:style style:name="Index" style:family="paragraph"
    style:parent-style-name="Standard" style:class="index">
    <style:properties style:font-name-complex="Tahoma1"
    text:number-lines="false" text:line-number="0"/>
    </style:style>
    <style:style style:name="__ChapterTitle" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" style:font-name-asian="Times New
    Roman" style:font-name-complex="Times New Roman"
    fo:text-indent="0inch" style:auto-text-indent="false"/>
    </style:style>
    <style:style style:name="__SectionTitle" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" style:font-name-asian="Times New
    Roman" style:font-name-complex="Times New Roman"
    fo:text-indent="0inch" style:auto-text-indent="false"/>
    </style:style>
    <style:style style:name="__Title" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" style:font-name-asian="Times New
    Roman" style:font-name-complex="Times New Roman"
    fo:text-indent="0inch" style:auto-text-indent="false"/>
    </style:style>
    <style:style style:name="__SubTitle1" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" style:font-name-asian="Times New
    Roman" style:font-name-complex="Times New Roman"
    fo:text-indent="0inch" style:auto-text-indent="false"/>
    </style:style>
    <style:style style:name="blockquote" style:family="paragraph">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.0835inch" fo:margin-bottom="0.0835inch"
    style:use-window-font-color="true" style:font-name="Arial Unicode MS"
    fo:font-size="12pt" fo:language="en" fo:country="US"
    style:font-name-asian="Arial Unicode MS" style:font-size-asian="12pt"
    style:font-name-complex="Arial Unicode MS"
    style:font-size-complex="12pt" style:language-complex="ar"
    style:country-complex="SA" fo:eek:rphans="2" fo:widows="2"
    fo:text-indent="0.2inch" style:auto-text-indent="false"/>
    </style:style>
    <style:style style:name="__Biography" style:family="paragraph">
    <style:properties fo:margin-left="0.4165inch"
    fo:margin-right="0.4165inch" fo:margin-top="0.0835inch"
    fo:margin-bottom="0.0835inch" style:use-window-font-color="true"
    style:font-name="Arial Unicode MS" fo:font-size="12pt"
    fo:language="en" fo:country="US" style:font-name-asian="Arial Unicode
    MS" style:font-size-asian="12pt" style:font-name-complex="Arial
    Unicode MS" style:font-size-complex="12pt" style:language-complex="ar"
    style:country-complex="SA" fo:eek:rphans="2" fo:widows="2"
    fo:text-indent="0.2inch" style:auto-text-indent="false"
    fo:padding="0.028inch" fo:border="0.0008inch solid #000000"/>
    </style:style>
    <style:style style:name="__Revised" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" fo:font-size="11pt"
    style:font-name-asian="Times New Roman" style:font-size-asian="11pt"
    style:font-name-complex="Times New Roman"
    style:font-size-complex="11pt" fo:text-indent="0inch"
    style:auto-text-indent="false" fo:background-color="#00ff00">
    <style:background-image/>
    </style:properties>
    </style:style>
    <style:style style:name="_FigNumber" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" fo:font-size="11pt"
    style:font-name-asian="Times New Roman" style:font-size-asian="11pt"
    style:font-name-complex="Times New Roman"
    style:font-size-complex="11pt" fo:text-indent="0inch"
    style:auto-text-indent="false" fo:background-color="#d8bfd8">
    <style:background-image/>
    </style:properties>
    </style:style>
    <style:style style:name="_FigTitle" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" fo:font-size="11pt"
    style:font-name-asian="Times New Roman" style:font-size-asian="11pt"
    style:font-name-complex="Times New Roman"
    style:font-size-complex="11pt" fo:text-indent="0inch"
    style:auto-text-indent="false" fo:background-color="#d8bfd8">
    <style:background-image/>
    </style:properties>
    </style:style>
    <style:style style:name="_FigLegend" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" fo:font-size="9pt"
    style:font-name-asian="Times New Roman" style:font-size-asian="9pt"
    style:font-name-complex="Times New Roman"
    style:font-size-complex="9pt" fo:text-indent="0inch"
    style:auto-text-indent="false" fo:background-color="#d8bfd8">
    <style:background-image/>
    </style:properties>
    </style:style>
    <style:style style:name="_FigCredit" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" fo:font-size="9pt"
    style:font-name-asian="Times New Roman" style:font-size-asian="9pt"
    style:font-name-complex="Times New Roman"
    style:font-size-complex="9pt" fo:text-indent="0inch"
    style:auto-text-indent="false" fo:background-color="#ffa500">
    <style:background-image/>
    </style:properties>
    </style:style>
    <style:style style:name="_error" style:family="paragraph"
    style:parent-style-name="Standard">
    <style:properties fo:margin-left="0inch" fo:margin-right="0inch"
    fo:margin-top="0.1945inch" fo:margin-bottom="0.1945inch"
    style:font-name="Times New Roman" fo:font-size="24pt"
    style:font-name-asian="Times New Roman" style:font-size-asian="24pt"
    style:font-name-complex="Times New Roman"
    style:font-size-complex="24pt" fo:text-indent="0inch"
    style:auto-text-indent="false" fo:background-color="#dc143c">
    <style:background-image/>
    </style:properties>
    </style:style>
    <style:style style:name="WW-Default Paragraph Font"
    style:family="text"/>
    <style:style style:name="_fig" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="12pt"
    style:text-background-color="#99ccff" style:font-size-asian="12pt"
    style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_fig_au" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:color="#3366ff" fo:font-size="12pt"
    style:font-size-asian="12pt" style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_figref" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="12pt"
    style:text-background-color="#ccffcc" style:font-size-asian="12pt"
    style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_figref_au" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:color="#008000" fo:font-size="12pt"
    style:font-size-asian="12pt" style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_figrefredisp" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="12pt" style:text-underline="single"
    style:text-underline-color="font-color"
    style:text-background-color="#33cccc" style:font-size-asian="12pt"
    style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_figrefredisp_au" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:color="#009999" fo:font-size="12pt"
    style:text-underline="single" style:text-underline-color="font-color"
    style:font-size-asian="12pt" style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_eqn" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="16pt"
    style:text-background-color="#ffcc00" style:font-size-asian="16pt"
    style:font-size-complex="16pt"/>
    </style:style>
    <style:style style:name="_eqn_au" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:color="#666699" fo:font-size="16pt"
    style:font-size-asian="16pt" style:font-size-complex="16pt"/>
    </style:style>
    <style:style style:name="_cite" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="12pt"
    style:text-background-color="#ff99cc" style:font-size-asian="12pt"
    style:font-size-complex="12pt"/>
    </style:style>
    <style:style style:name="_ilink" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="14pt"
    style:text-background-color="#ff99cc" style:font-size-asian="14pt"
    style:font-size-complex="14pt"/>
    </style:style>
    <style:style style:name="_elink" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="14pt"
    style:text-background-color="#99cc00" style:font-size-asian="14pt"
    style:font-size-complex="14pt"/>
    </style:style>
    <style:style style:name="_keyterm" style:family="text"
    style:parent-style-name="WW-Default Paragraph Font">
    <style:properties fo:font-size="12pt"
    style:text-background-color="#ff7c80" style:font-size-asian="12pt"
    style:font-size-complex="12pt"/>
    </style:style>
    <text:eek:utline-style>
    <text:eek:utline-level-style text:level="1" style:num-format=""/>
    <text:eek:utline-level-style text:level="2" style:num-format=""/>
    <text:eek:utline-level-style text:level="3" style:num-format=""/>
    <text:eek:utline-level-style text:level="4" style:num-format=""/>
    <text:eek:utline-level-style text:level="5" style:num-format=""/>
    <text:eek:utline-level-style text:level="6" style:num-format=""/>
    <text:eek:utline-level-style text:level="7" style:num-format=""/>
    <text:eek:utline-level-style text:level="8" style:num-format=""/>
    <text:eek:utline-level-style text:level="9" style:num-format=""/>
    <text:eek:utline-level-style text:level="10" style:num-format=""/>
    </text:eek:utline-style>
    <text:footnotes-configuration style:num-format="1"
    text:start-value="0" text:footnotes-position="page"
    text:start-numbering-at="document"/>
    <text:endnotes-configuration style:num-format="i"
    text:start-value="0"/>
    <text:linenumbering-configuration text:number-lines="false"
    text:eek:ffset="0.1965inch" style:num-format="1"
    text:number-position="left" text:increment="5"/>
    </office:styles>
    <office:automatic-styles>
    <style:style style:name="P1" style:family="paragraph"
    style:parent-style-name="__ChapterTitle"
    style:master-page-name="Standard">
    <style:properties fo:font-size="24pt" style:letter-kerning="true"
    style:font-size-asian="24pt" style:font-size-complex="24pt"
    style:page-number="0"/>
    </style:style>
    <style:style style:name="P2" style:family="paragraph"
    style:parent-style-name="__SectionTitle">
    <style:properties fo:font-size="18pt" style:font-size-asian="18pt"
    style:font-size-complex="18pt"/>
    </style:style>
    <style:page-master style:name="pm1">
    <style:properties fo:page-width="8.5inch" fo:page-height="11inch"
    style:num-format="1" style:print-orientation="portrait"
    fo:margin-top="1inch" fo:margin-bottom="1inch"
    fo:margin-left="1.25inch" fo:margin-right="1.25inch"
    style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0"
    style:layout-grid-lines="36"
    style:layout-grid-base-height="0.1945inch"
    style:layout-grid-ruby-height="0.0555inch"
    style:layout-grid-mode="none" style:layout-grid-ruby-below="false"
    style:layout-grid-print="false" style:layout-grid-display="false"
    style:footnote-max-height="0inch">
    <style:footnote-sep style:width="0.0071inch"
    style:distance-before-sep="0.0398inch"
    style:distance-after-sep="0.0398inch" style:adjustment="left"
    style:rel-width="25%" style:color="#000000"/>
    </style:properties>
    <style:header-style/>
    <style:footer-style/>
    </style:page-master>
    </office:automatic-styles>
    <office:master-styles>
    <style:master-page style:name="Standard"
    style:page-master-name="pm1"/>
    </office:master-styles>
    <office:body>
    <text:sequence-decls>
    <text:sequence-decl text:display-outline-level="0"
    text:name="Illustration"/>
    <text:sequence-decl text:display-outline-level="0"
    text:name="Table"/>
    <text:sequence-decl text:display-outline-level="0"
    text:name="Text"/>
    <text:sequence-decl text:display-outline-level="0"
    text:name="Drawing"/>
    </text:sequence-decls>
    <text:p text:style-name="P1">Genes are DNA</text:p>
    <text:p text:style-name="P2">
    <text:bookmark-start text:name="N10004"/>Introduction </text:p>
    </office:body>
    </office:document>
    Richard Bondi, Aug 25, 2004
    #1
    1. Advertising

  2. By the way, the same xsl works just find with jdom (beta 9); the code
    fragment is shown below. I think jdom's XPath just uses XPathAPI under
    the covers, so I must be using XPathAPI incorrectly -- but I can't
    figure out how.

    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.Namespace;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.XMLOutputter;
    import org.jdom.xpath.XPath;

    import javax.xml.transform.TransformerException;
    import java.io.File;
    import java.io.IOException;
    import java.io.StringReader;

    ....
    SAXBuilder _sax = new SAXBuilder();
    Document _oodoc = _sax.build(new File("... the file from the previous
    post..."));

    String xsl = "... xsl in the previous post ..."
    // And this works perfectly, selecting exactly
    // the nodes it is supposed to:
    List sectionTitles = XPath.selectNodes(_oodoc, xsl);
    ....

    (However, I'm a bit fed up with jdom and don't like using it: in beta
    8, setContent() didn't work but XPath did; in beta 9, setContent() now
    works, but XPath is suddenly broken for the ancestor:: axis, and based
    on the mailing list posts, nobody is planning to fix it for 1.0. And I
    really don't want to mix and match jdom and non-jdom xml code in my
    packages.)
    Richard Bondi, Aug 26, 2004
    #2
    1. Advertising

  3. Richard Bondi, Aug 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve W. Jackson

    Re: XPathAPI: a query that returns an int ?

    Steve W. Jackson, Jul 17, 2003, in forum: Java
    Replies:
    2
    Views:
    461
    Steve W. Jackson
    Jul 18, 2003
  2. Joona I Palaste

    Xalan XPathAPI question

    Joona I Palaste, Jan 7, 2004, in forum: Java
    Replies:
    11
    Views:
    2,863
    Mike Schilling
    Jan 11, 2004
  3. frank
    Replies:
    2
    Views:
    5,908
    Roedy Green
    Jan 30, 2006
  4. sheldonlg

    Obeying only part of a style

    sheldonlg, Feb 28, 2008, in forum: HTML
    Replies:
    3
    Views:
    335
    Bergamot
    Feb 28, 2008
  5. Mia
    Replies:
    4
    Views:
    117
    Dr.Ruud
    Sep 12, 2006
Loading...

Share This Page