Package org.docx4j.openpackaging.parts
Class XmlPart
java.lang.Object
org.docx4j.openpackaging.Base
org.docx4j.openpackaging.parts.Part
org.docx4j.openpackaging.parts.XmlPart
- 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 Summary
Fields Modifier and Type Field Description protected org.w3c.dom.Document
doc
This part's XML contents.protected static org.slf4j.Logger
log
Fields inherited from class org.docx4j.openpackaging.Base
contentType, partName, relationships
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description java.lang.String
cachedXPathGetString(java.lang.String xpath, java.lang.String prefixMappings)
(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.void
discardCacheXPathObject()
abstract org.w3c.dom.Document
getDocument()
java.lang.String
getXML()
Get the XML as a String.boolean
isContentEqual(Part other)
void
setDocument(java.io.InputStream is)
void
setDocument(org.w3c.dom.Document doc)
boolean
setNodeValueAtXPath(java.lang.String xpath, java.lang.String value, java.lang.String prefixMappings)
Set the value of the node referenced in the xpath expression.java.util.List<org.w3c.dom.Node>
xpathGetNodes(java.lang.String xpathString, java.lang.String prefixMappings)
java.lang.String
xpathGetString(java.lang.String xpathString, java.lang.String prefixMappings)
Note: If the result is an empty node-set, it will be converted to an empty string, rather than null.Methods inherited from class org.docx4j.openpackaging.parts.Part
getContentLengthAsLoaded, getOwningRelationshipPart, getPackage, getRelationshipType, getSourceRelationship, getSourceRelationships, getVersion, remove, rename, setContentLengthAsLoaded, setOwningRelationshipPart, setPackage, setPartShortcut, setRelationshipType, setSourceRelationship, setVersion
Methods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, reset, setContentType, setPartName, setRelationships, setUserData
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
log
protected static org.slf4j.Logger log -
doc
protected org.w3c.dom.Document docThis 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
-
XmlPart
- Throws:
InvalidFormatException
-
XmlPart
- Throws:
InvalidFormatException
-
-
Method Details
-
setDocument
- Throws:
Docx4JException
-
setDocument
public void setDocument(org.w3c.dom.Document doc) -
getDocument
- Throws:
Docx4JException
-
getXML
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 Docx4JExceptionNote: 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 Docx4JExceptionSet 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
- Specified by:
isContentEqual
in classPart
- Throws:
Docx4JException
-