odftoolkit icon indicating copy to clipboard operation
odftoolkit copied to clipboard

Add FAQ - How to access a specific ODT file and to do the required manipulation.

Open Muhammedismail opened this issue 4 years ago • 1 comments

I have loaded an ODT file and trying to access the specific elements for the desired manipulation (editing and adding some data content)

But I am unable to get that

this is how I am trying to access the specific element: but I do have an issue with the OdfNamespace(), can anyone please give me any guide or a sample code for how to access a specific element to do the manipulation, if not this way or any other way please, basically I need to access the table content.

and I got the below from the Odf document.

OdfPackage pkg = OdfPackage.loadPackage(documentPath);
	OdfTextDocument odt = (OdfTextDocument) OdfDocument.loadDocument(documentPath);
	



	  XPath xpath = XPathFactory.newInstance().newXPath();
	  xpath.setNamespaceContext(new  OdfNamespace());
	  OdfFileDom dom = odt.getContentDom();
	  firstParagraph = (TextPElement) xpath.evaluate("//text:p[1]", dom, XPathConstants.NODE);

it would be really great if anybody can give me any hint or guidance, thanks.

Muhammedismail avatar Jun 09 '21 09:06 Muhammedismail

@Muhammedismail Hej, I take this as a documentation issue. I usually start to look in existing tests to copy/paste existing code and you might want to take a look at least into the following three:

  1. https://github.com/tdf/odftoolkit/blob/master/odfdom/src/test/java/org/odftoolkit/odfdom/dom/XPathTest.java
  2. https://github.com/tdf/odftoolkit/blob/master/odfdom/src/test/java/org/odftoolkit/odfdom/doc/text/OdfParagraphTest.java
  3. https://github.com/tdf/odftoolkit/blob/master/odfdom/src/test/java/org/odftoolkit/odfdom/doc/text/OdfSpanTest.java

An easy consistent high-level API is the next big thing for the 1.0.0

svanteschubert avatar Jul 01 '21 07:07 svanteschubert