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
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
FieldsModifier and TypeFieldDescriptionprotected DocumentThis part's XML contents.protected static org.slf4j.LoggerFields inherited from class org.docx4j.openpackaging.Base
contentType, partName, relationships -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncachedXPathGetString(String xpath, 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.voidabstract DocumentgetXML()Get the XML as a String.booleanisContentEqual(Part other) voidvoidsetDocument(Document doc) booleansetNodeValueAtXPath(String xpath, String value, String prefixMappings) Set the value of the node referenced in the xpath expression.xpathGetNodes(String xpathString, String prefixMappings) xpathGetString(String xpathString, 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, setVersionMethods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, reset, setContentType, setPartName, setRelationships, setUserData
-
Field Details
-
log
protected static org.slf4j.Logger log -
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
-
XmlPart
- Throws:
InvalidFormatException
-
XmlPart
- Throws:
InvalidFormatException
-
-
Method Details
-
setDocument
- Throws:
Docx4JException
-
setDocument
-
getDocument
- Throws:
Docx4JException
-
getXML
Get the XML as a String.- Throws:
Docx4JException- Since:
- 3.0.1
-
xpathGetString
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
(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
public void discardCacheXPathObject() -
xpathGetNodes
-
setNodeValueAtXPath
public boolean setNodeValueAtXPath(String xpath, String value, 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
- Specified by:
isContentEqualin classPart- Throws:
Docx4JException
-