none
What's the minimal requirements for an valid empty WordprocessingDocument,which can be parsed correctly by Word 2007? RRS feed

  • Question

  • What's the minimal requirements for an valid empty WordprocessingDocument,which can be parsed correctly by Word 2007?

    which parts shall be included and what minimal xml shall be fed into these parts?
    Monday, October 12, 2009 3:34 PM

Answers

  • You only need to have the main document part within a Word package. Here is an example of a min valid Word document:


    public void HelloWorld(string docName)

    {
      // Create a Wordprocessing document.
      using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
      {
        // Add a new main document part.
        package.AddMainDocumentPart();

        // Create the Document DOM.
        package.MainDocumentPart.Document =
          new Document(
            new Body(
              new Paragraph(
                new Run(
                  new Text("Hello World!")))));

        // Save changes to the main document part.
        package.MainDocumentPart.Document.Save();
      }
    }


    Zeyad Rajabi (MS)
    • Marked as answer by Xiaoyuvax Tuesday, October 13, 2009 3:44 PM
    Monday, October 12, 2009 9:31 PM

All replies

  • You only need to have the main document part within a Word package. Here is an example of a min valid Word document:


    public void HelloWorld(string docName)

    {
      // Create a Wordprocessing document.
      using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
      {
        // Add a new main document part.
        package.AddMainDocumentPart();

        // Create the Document DOM.
        package.MainDocumentPart.Document =
          new Document(
            new Body(
              new Paragraph(
                new Run(
                  new Text("Hello World!")))));

        // Save changes to the main document part.
        package.MainDocumentPart.Document.Save();
      }
    }


    Zeyad Rajabi (MS)
    • Marked as answer by Xiaoyuvax Tuesday, October 13, 2009 3:44 PM
    Monday, October 12, 2009 9:31 PM
  • don't need to add the Body.sectPr Node?  it is told in the SDK PPT materials that a sectPr must exist in the maindocument's Body Node.

    Tuesday, October 13, 2009 5:59 AM
  • The example above is the minimum amount of xml needed to be understood by Word. According to the ISO standard and schema the minimal set is different. I would recommend consulting the standard and schema to figure out what is need in that case.


    Zeyad Rajabi (MS)
    Tuesday, October 13, 2009 10:57 PM
  • From Open XML The markup explained by Wouter van Vugt:


    "The minimal WordprocessingML document is required to have at least three parts. You need to have one part that defines the main document body, usually called
    document.xml. This part needs to store its content type in the content-types part. Every package contains exactly one content-types part. Finally, the main body parts needs to be locatable by using a relationship part. This is the third one to go into the package.

    To create the initial empty document, first create an empty directory. Inside this empty directory, create a new subdirectory called _rels. Don't forget the underscore, the name is important. In the empty root directory, you store two files, the content-types list, and main document part. In the _rels subfolder, the third relationship part is stored. The main document part can actually be stored in any directory of your liking, as long as the relationship will point to it correctly. The root directory is just used for the ease of it. Microsoft Office Word® 2007 uses the word subfolder. Other applications can freely choose any other directory they see fit."

    • Proposed as answer by salgo60 Thursday, October 15, 2009 8:53 AM
    Thursday, October 15, 2009 8:53 AM