Let's talk t, p, and r

 So, now that I have decided to take my WordML skills to the next level it also affords me that chance to answer some of the questions that regularly come through my inbox.

Managing the content for the Office Developer Center site has a lot of benefits, and one of them is that I’m in the loop on a lot of questions, both internal and external. One things is clear to me: WordML is “Hot, Hot, Hot” ( please name the band that wrote a song with this title. The prize is that I will respect you more for knowing about this great band).

 

When you save your documents in WordML format and then peek at the XML, you may find the verbosity of the XML and the number of tags a little arresting at first. That’s OK- just relax and know that there are three main workhorses for the bulk of Word markup: give me t, give me a r, give me an p! (you can download the XML schema reference for Office from our download center if you want to truly dig into the schemas). The <t> element encapsulates text. That’s it. Pure and simple. Any and all text goes between <t></t> tags. The <r> element is for runs of text. Often, it contains a bunch of <t> elements (which have all of the text). Informally said, it is a way of grouping <t> elements, applying styles to the run of text etc. The <p> element encapsulates a paragraph of text. No big news here.

 

Here is some text I typed in Word:

 

This is some text. We will look at how it gets divided up.

This is a second paragraph with bold!

 

Here is what the WordML markup looks like (I dropped off declarations, processing instructions, and other preamble info):

<w:body>

  <wx:sect>

    <w:p>

      <w:r>

        <w:t>This is some text. We will look at how it gets divided up.</w:t>

      </w:r>

    </w:p>

    <w:p>

      <w:r>

        <w:t>This is a second paragraph with </w:t>

      </w:r>

      <w:r>

        <w:rPr>

         <w:b/>

        </w:rPr>

        <w:t>bold</w:t>

      </w:r>

      <w:r>

        <w:t>!</w:t>

      </w:r>

    </w:p>

</w:body>

 

As you can see, it’s pretty straight-forward. But, why should you care? Well, think XSLT! You can create Word documents from any well-formed XML file. You can turn Word documents into another XML structure. This is a hint of what it’s all about.

 

Rock on.