tags:

views:

153

answers:

1

I'm new to the world of XML. I'm not sure which way to build the XML so I provided 2 examples below.

My question is: Given the XML, how do I transform either Example#1 / #2 to the WordML Result? What technologies do I need to accomplish this?

Example#1:

<NumberedList1>
  <Paragraph>Paragraph one.</Paragraph>
</NumberedList1>

Example#2:

<NumberedList>1</NumberedList>
<Paragraph>Paragraph one.</Paragraph>

After transformation...

WordML Result:

<w:p>
  <w:pPr>
    <w:pStyle w:val="ListParagraph"/>
    <w:numPr>
      <w:ilvl w:val="0"/>
      <w:numId w:val="1"/>
    </w:numPr>
  </w:pPr>
  <w:r>
    <w:t>Paragraph one.</w:t>
  </w:r>
</w:p>

If there is a way to transform the XML to WordML, maybe I can opt to save the data in XML format in the db instead of building both XML and WordML on the fly for 2 different formats.

+1  A: 

When you say "transform" in the context of XML, that inevitably leads you to use XSLT.

(Let me also mention that if you are considering either of those two examples as your XML design, it's very bad form to have part of an element name mean something. Example #2 is far superior.)

Paul Clapham
Ok, just needed that confirmation about using XSLT. But given that I need a fair amount of flexibility in building the WordML document, I'm doubtful about using XSLT at all. Rather than rely on XML/XSLT to render the file document, would most experienced XML/XSLT veterans recommend querying from the relational db and building the WordML document with ASP/PHP scripting for ultimate flexibility in document generation? Or is XML/XSLT enough for just about any kind of scenario you can throw at it?
Level1Coder
In general if you're generating XML, I would recommend a tool which understands XML. Otherwise you're going to be stumbling over unescaped ampersands and things like that. Being able to produce an unescaped ampersand in an XML document is flexibility you don't need.
Paul Clapham
Thanks for the heads up about unescaped ampersands. Finally I decided to directly build WordML with PHP rather than building XML then transform to WordML which is an extra step. There are just too many variables that will affect the final layout design and formatting of the document and I don't think XSLT is up for this task.
Level1Coder