Class XPathHelper


  • public final class XPathHelper
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.xml.xpath.XPathFactory getFactory()  
      static <T extends XmlObject>
      T
      selectProperty​(XmlObject startObject, java.lang.Class<T> resultClass, XSLFShape.ReparseFactory<T> factory, javax.xml.namespace.QName[]... path)
      Internal code - API may change any time!
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getFactory

        public static javax.xml.xpath.XPathFactory getFactory()
      • selectProperty

        @Internal
        public static <T extends XmlObject> T selectProperty​(XmlObject startObject,
                                                             java.lang.Class<T> resultClass,
                                                             XSLFShape.ReparseFactory<T> factory,
                                                             javax.xml.namespace.QName[]... path)
                                                      throws XmlException
        Internal code - API may change any time!

        The XSLFShape.selectProperty(Class, String) xquery method has some performance penalties, which can be workaround by using XmlCursor. This method also takes into account that AlternateContent tags can occur anywhere on the given path.

        It returns the first element found - the search order is:

        • searching for a direct child
        • searching for a AlternateContent.Choice child
        • searching for a AlternateContent.Fallback child
        The factory flag is a workaround to process files based on a later edition. But it comes with the drawback: any change on the returned XmlObject aren't saved back to the underlying document - so it's a non updatable clone. If factory is null, a XmlException is thrown if the AlternateContent is not allowed by the surrounding element or if the extracted object is of the generic type XmlAnyTypeImpl.
        Parameters:
        resultClass - the requested result class
        factory - a factory parse method reference to allow reparsing of elements extracted from AlternateContent elements. Usually the enclosing XmlBeans type needs to be used to parse the stream
        path - the elements path, each array must contain at least 1 QName, but can contain additional alternative tags
        Returns:
        the xml object at the path location, or null if not found
        Throws:
        XmlException - If factory is null, a XmlException is thrown if the AlternateContent is not allowed by the surrounding element or if the extracted object is of the generic type XmlAnyTypeImpl.
        Since:
        POI 4.1.2