Class XPathOverDir

java.lang.Object
org.docx4j.samples.XPathOverDir

public class XPathOverDir extends Object
  • Constructor Details

    • XPathOverDir

      public XPathOverDir()
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Example of how to find an object in document.xml via XPath. As explained in Getting Started, there are limitations in the JAXB reference implementation which make this approach buggy: 1. the xpath expressions are evaluated against the XML document as it was when first opened in docx4j. You can update the associated XML document once only, by passing true into getJAXBNodesViaXPath. Updating it again (with current JAXB 2.1.x or 2.2.x) will cause an error. 2. For some objects,JAXB can’t get parent (with getParent) 3. For some document, JAXB can’t set up the XPath at all! If these problems affect you, you could try using MOXy as your JAXB implementation (which docx4j supports as from forthcoming docx4j 3.0). See http://www.docx4java.org/forums/docx-java-f6/moxy-t1242.html Alternatively, the tried and tested approach is to use TraversalUtil; see the OpenMainDocumentAndTraverse sample.
      Throws:
      Exception
    • xpathQuery

      private static void xpathQuery(JaxbXmlPartXPathAware part, String xpath) throws XPathBinderAssociationIsPartialException, jakarta.xml.bind.JAXBException
      Throws:
      XPathBinderAssociationIsPartialException
      jakarta.xml.bind.JAXBException