2

So I am trying to get an flat file XML version of an OPC document.

I am using OPCPackage from org.apache.poi.openxml4j

In C++ you there is a call that creates flat XML file from this zipped file.

Anyone knows how to do that in Java?

Also any good read related to OPC and Java would be awesome.

Thanks a lot

Cheers

UPDATE: related to the comment i made to only answer...

code

    // imports
    import org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator;
    import org.docx4j.openpackaging.packages.WordprocessingMLPackage;

    // code snippet
    WordprocessingMLPackage wmlPkg = null;
    try 
    {
        wmlPkg = WordprocessingMLPackage.load(inFile);
    } 
    catch (Docx4JException ex) 
    {
        //...
    }

    FlatOpcXmlCreator flatOpcWorker = new FlatOpcXmlCreator((wmlPkg));

    flatOpcWorker.marshal(new FileOutputStream(tmpFlatFile.getAbsolutePath()));

So thats code snippet and it results in compile error:

cannot find symbol symbol: method marshal(java.io.FileOutputStream) location: variable flatOpcWorker of type org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
grobartn
  • 3,510
  • 11
  • 40
  • 52

1 Answers1

2

My project docx4j has a FlatOpcXmlCreator which does this; see the ConvertOutFlatOpenPackage sample

If you want to use it with POI (which uses XML Beans, not JAXB), I guess you could port it. Both projects are ASL, and both do the OPC part based on OpenXML4J.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • the problem is this is not an docx. Its OPC based format. Will that work well with OPC general format. I am asking because I am not sure how Docx specific is your project. And not sure how different if at all is docx opc is different from other opc based formats – grobartn Apr 12 '12 at 14:37
  • There is nothing docx specific about it, the constructor takes a OpcPackage, and it has been tested and works with pptx and xlsx. – JasonPlutext May 28 '12 at 22:54
  • so I am trying your example and i get error on this line worker.marshal(new FileOutputStream(outputfilepath) it says marshal "cannot find symbol symbol: method marshal(java.io.FileOutputStream) location: variable flatOpcWorker of type org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator" do you know why it would say so – grobartn May 29 '12 at 22:52
  • I think you need to pose a new question, which includes the Java code you are using, the input you are providing, and the resulting stack trace. – JasonPlutext May 30 '12 at 08:53
  • changed it please review and answer ... i am trying to get that working so i can award you bounty ... – grobartn May 30 '12 at 14:21
  • You are using a version of docx4j before that convenience method was added: https://github.com/plutext/docx4j/commit/7865fa2e558d072ae07c298ce5610078e1528cf6 Try 2.8.0. – JasonPlutext Jun 05 '12 at 22:39