我将docx4j从2.8版更新到了3.1.0版,但是我有一个CustomXmlDataStoragePart和CustomXmlPart类型的问题。以下代码是我的应用程序2.8.0版中的原始代码:
HashMap<String, CustomXmlDataStoragePart> customXmlDataStorageParts = wml.getCustomXmlDataStorageParts();
for (String string : customXmlDataStorageParts.keySet()) {
CustomXmlDataStoragePart customXmlDataStoragePart = customXmlDataStorageParts.get(string);
customXmlDataStoragePart.getData().setDocument(inputStream);
}
但是从3.0版开始,他们将getCustomXmlDataStorageParts()从CustomXmlDataStoragePart更改为CustomXmlPart,但是CustomXmlPart没有getData(),因此我无法直接用inputStream设置文档。现在如何让CustomXmlPart从inputStream获得XML?谢谢!
最佳答案
CustomXmlPart是一个接口:
/**
* There are two types of these:
* - JaxbCustomXmlDataStoragePart<E>
* - CustomXmlDataStoragePart
*
* This interface doesn't provide getData,
* because the 2 types are quite different.
*
* But it could allow storeItemId to be
* get or set.
*
* @author jharrop
*
*/
public interface CustomXmlPart
如果您有CustomXmlDataStoragePart,则可以强制转换为该变量。