我有一个代码:
// -----------------------------------------------------------------
TextDocument resDoc = TextDocument.loadDocument( someInputStream );
Section section = resDoc.getSectionByName( "Section1" ); // this section does exist in the document
// create new node form String
String fragment = "<text:p text:style-name=\"P13\"><text:span text:style-name=\"T1\">Test</text:span></text:p>";
Node node = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new InputSource( new StringReader( fragment ) ) ).getDocumentElement();
node = section.getOdfElement().getOwnerDocument().importNode( node, true );
// append new node into section
section.getOdfElement().appendChild( node );
// -----------------------------------------------------------------
代码运行没有问题。但是结果文档的部分中没有出现任何内容。请知道如何将从字符串创建的新节点添加到 odf 文档中?