Page 1 of 1

How to find right part of custom XML to overwrite?

PostPosted: Tue Apr 10, 2012 9:13 am
by shobull
Hi,

I'm generating many word documents using repeating sections, but I need every document with different datas (different xml files). I've made docx template and bound XML file with testing data. Now I'd like to rewrite XML file with new one, but in customXml folder, there are item1.xml, item2.xml, item3.xml and item4.xml. How can I found out IN PROGRAM, which file should I rewrite? (Of course, I can find the right file unzipping and opening the files, but I want to find it in my program, because first time item1.xml was the file with data, but second time it was item3.xml).

Thanks for all answers!

Re: How to find right part of custom XML to overwrite?

PostPosted: Wed Apr 11, 2012 1:52 pm
by jason
See https://github.com/plutext/OpenDoPE-WAR and in particular CustomXmlUtils.

The pattern is:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
// Find custom xml item id
                String itemId = CustomXmlUtils.getCustomXmlItemId(wordMLPackage).toLowerCase();
                System.out.println("Looking for item id: " + itemId);

                // Inject data_file.xml        
                CustomXmlDataStoragePart customXmlDataStoragePart
                        = wordMLPackage.getCustomXmlDataStorageParts().get(itemId);
                if (customXmlDataStoragePart==null) {
                        throw new WebApplicationException(
                                        new Docx4JException("Couldn't find CustomXmlDataStoragePart"),
                                        Status.UNSUPPORTED_MEDIA_TYPE);
                }
                customXmlDataStoragePart.getData().setDocument(xis);
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4

Re: How to find right part of custom XML to overwrite?

PostPosted: Sat Apr 14, 2012 10:53 pm
by shobull
Thanx Jason for your quick reply. It helped me a lot! :geek: