Class XPathAwareCloner

java.lang.Object
org.docx4j.utils.XPathAwareCloner

public class XPathAwareCloner extends Object
Some users wish to be able to use an XPath on the result of cloning a JAXB object. This variant on XmlUtils.deepCopy allows that. Note that if you use this object's deepCopy method more than once, the results returned by getJAXBNodesViaXPath will only be on your last deepCopy.
  • Constructor Details

    • XPathAwareCloner

      public XPathAwareCloner()
  • Method Details

    • deepCopy

      public Object deepCopy(Object o)
      Clone this JAXB object, using default JAXBContext.
    • deepCopy

      public Object deepCopy(Object o, jakarta.xml.bind.JAXBContext jc)
      Clone this JAXB object
      Parameters:
      value -
      jc -
      Returns:
    • getBinder

      public jakarta.xml.bind.Binder<Node> getBinder()
      Enables synchronization between XML infoset nodes and JAXB objects representing same XML document. An instance of this class maintains the association between XML nodes of an infoset preserving view and a JAXB representation of an XML document. Navigation between the two views is provided by the methods getXMLNode(Object) and getJAXBNode(Object) . In theory, modifications can be made to either the infoset preserving view or the JAXB representation of the document while the other view remains unmodified. The binder ought to be able to synchronize the changes made in the modified view back into the other view using the appropriate Binder update methods, #updateXML(Object, Object) or #updateJAXB(Object). But JAXB doesn't currently work as advertised .. access to this object is offered for advanced users on an experimental basis only.
    • getJAXBNodesViaXPath

      public List<Object> getJAXBNodesViaXPath(String xpathExpr, boolean refreshXmlFirst) throws jakarta.xml.bind.JAXBException, XPathBinderAssociationIsPartialException
      Fetch JAXB Nodes matching an XPath (for example "//w:p"). If you have modified your JAXB objects (eg added or changed a w:p paragraph), you need to update the association. The problem is that this can only be done ONCE, owing to a bug in JAXB: see https://jaxb.dev.java.net/issues/show_bug.cgi?id=459 So this is left for you to choose to do via the refreshXmlFirst parameter.
      Parameters:
      xpathExpr -
      refreshXmlFirst -
      Returns:
      Throws:
      jakarta.xml.bind.JAXBException
      XPathBinderAssociationIsPartialException
    • main

      public static void main(String[] args) throws jakarta.xml.bind.JAXBException, XPathBinderAssociationIsPartialException
      Parameters:
      args -
      Throws:
      jakarta.xml.bind.JAXBException
      XPathBinderAssociationIsPartialException