Class XmlPart

java.lang.Object
Direct Known Subclasses:
ActiveXControlXmlPart, CustomXmlDataStorageImpl, DefaultXmlPart

public abstract class XmlPart
extends Part
OPC Parts are either XML, or binary (or text) documents. Most are XML documents. docx4j aims to represent XML parts using JAXB. However, at present there are some parts for which we don't have JAXB representations. Until such time as a JAXB representation for an XML Part exists, the Part should extend this class.
  • Field Details

    • log

      protected static org.slf4j.Logger log
    • doc

      protected org.w3c.dom.Document doc
      This part's XML contents. Not guaranteed to be up to date. Whether it is or not will depend on how the class which extends Part chooses to treat it. It may be that the class uses some other internal representation for its data.
  • Constructor Details

  • Method Details

    • setDocument

      public void setDocument​(java.io.InputStream is) throws Docx4JException
      Throws:
      Docx4JException
    • setDocument

      public void setDocument​(org.w3c.dom.Document doc)
    • getDocument

      public abstract org.w3c.dom.Document getDocument() throws Docx4JException
      Throws:
      Docx4JException
    • getXML

      public java.lang.String getXML() throws Docx4JException
      Get the XML as a String.
      Throws:
      Docx4JException
      Since:
      3.0.1
    • xpathGetString

      public java.lang.String xpathGetString​(java.lang.String xpathString, java.lang.String prefixMappings) throws Docx4JException
      Note: If the result is an empty node-set, it will be converted to an empty string, rather than null.
      Parameters:
      xpathString -
      prefixMappings -
      Returns:
      Throws:
      Docx4JException
    • cachedXPathGetString

      public java.lang.String cachedXPathGetString​(java.lang.String xpath, java.lang.String prefixMappings) throws Docx4JException
      (Unless you are using Saxon as your XPath implementation (XPathFactoryUtil.setxPathFactory)) this uses org.apache.xpath.CachedXPathAPI for better performance, since Apache's old XPathAPI class, have the drawback of instantiating a new XPathContext (and thus building a new DTMManager, and new DTMs) each time it was called. XPathAPIObject instead retains its context as long as the object persists, reusing the DTMs. If you are using Saxon, then the cache won't be used.
      Parameters:
      xpath -
      prefixMappings -
      Returns:
      Throws:
      Docx4JException
      Since:
      3.3.1
      See Also:
      discardCacheXPathObject()
    • discardCacheXPathObject

      public void discardCacheXPathObject()
    • xpathGetNodes

      public java.util.List<org.w3c.dom.Node> xpathGetNodes​(java.lang.String xpathString, java.lang.String prefixMappings)
    • setNodeValueAtXPath

      public boolean setNodeValueAtXPath​(java.lang.String xpath, java.lang.String value, java.lang.String prefixMappings) throws Docx4JException
      Set the value of the node referenced in the xpath expression.
      Parameters:
      xpath -
      value -
      prefixMappings - a string such as "xmlns:ns0='http://schemas.medchart'"
      Returns:
      Throws:
      Docx4JException
    • isContentEqual

      public boolean isContentEqual​(Part other) throws Docx4JException
      Specified by:
      isContentEqual in class Part
      Throws:
      Docx4JException