3

I have a xml file which I need to open with Microsoft Word 2007. I wrote it on my own. But when I try to open it tells "Some parts are missing or invalid". I think this happens my document does not have all the requied properties defined. So I need to know what are the must-haves for an xml document to be able to be opened with Word 2007. I have following properties defined.

cp:coreProperties
w:settings
w:body

(The body has a simple text line.) What else need to be included? Thanks in advance.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
harsh
  • 2,399
  • 9
  • 29
  • 47
  • If creating the file the way you do it now is too difficult to straighten out, a better option might be to use Microsoft's OpenXML SDK. It's pretty straightforward to create valid documents, just have a look at the samples provided in the online help of the SDK. – Dirk Vollmar Jun 19 '12 at 17:57

1 Answers1

3

Expressed as Flat OPC XML, it can be as simple as:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
  <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
    <pkg:xmlData>
      <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
        <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
      </Relationships>
    </pkg:xmlData>
  </pkg:part>
  <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
    <pkg:xmlData>
      <w:document mc:Ignorable="w14 wp14" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
        <w:body>
          <w:p >
            <w:r>
              <w:t>Hello world</w:t>
            </w:r>
          </w:p>
        </w:body>
      </w:document>
    </pkg:xmlData>
  </pkg:part>
</pkg:package>

Are you including a relationship, but missing its target part? Or including a relId somewhere, but missing the relationship entirely?

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • thanks, what are essentials here? To be more precise, what I want is to add the conents of the zip file you get from the document in to a single xml document so that I can again open it from Word 2007. (The xml files in _rels, customXml, docProps and word folders need to be put into one xml file and open it with Word 2007). I know the resulting document will be large but I need to do that. – harsh Jun 18 '12 at 08:24
  • In Word, save as XML. That's give you the Flat OPC XML. Then you can remove everything you don't want. Just make sure that if you remove a part, you remove any relationship pointing to it. And if it has a rels part of its own, you remove that and all dependent parts. A little tedious to do manually, but quite easy. – JasonPlutext Jun 19 '12 at 22:46
  • thanks a lot. I will check that and let you know if it works. Thanks a lot for the support. – harsh Jun 20 '12 at 17:01