Monday, January 11, 2010

HINT: Styling documents for dedicated XML

Have you ever been challenged by your customer to create a special XML format from his documents? Have you tried to dig into InDesign's "Styles to XML mapping"? Tedious!

Try this way:
Ask your customer for an example XML document AND the technical XML reference OR a complete example containing ALL possible XML elements.
Make a list of all XML elements that may appear by opening the example document with a plain text editor. Collect all the names enclosed within < and > and comment the meaning of this name (element).

If your list now contains 12 element names you also need 12 different styles in InDesign to mark the text. Style sheets are the one and only way in InDesign to also mark the MEANING (not only the look and feel) of a text part.

Let's proceed with an example (my favorite one - a fraction of a DocBook XML):
Assume you have to deliver this XML output:
<citation>
    <authorname type="first">Andreas</authorname>
    <authorname type="last">Imhof</authorname>
    <year>2010</year>
    <title>Amazing XML</title>
    <publicationname>My Blog</publicationname>
</citation>
5 different XML elements within <citation> containing text information. Each text information in the InDesign document must be marked with its own style (paragraph or character style) to be able to identify the meaning of the text and to map it into the XML element.

Now complete your XML elements list by writing the style name besides the element name. Example:
<authorname type="last"> = authName
Means: The content marked with character style 'authName' goes into XML element <authorname type="last">.
<authorname type="first"> = authFirstName
Means: The content marked with character style 'authFirstName' goes into XML element <authorname type="first">.
... and so on... the hard part is done.

Create your InDesign document and strictly mark the textual content with these styles from the list.

Two ways to get the content out of InDesign:
#1. Use InDesign's built in "Styles to XML" tagging feature and export the document.

It may happen, that InDesign's build in XML export feature does not fulfill all your needs. In that case:
#2. use a third party document exporter to bring the content out of InDesign.
If you use BatchXSLT for InDesign as the document exporter, you do not need the "Styles to XML" tagging mentioned in way #1. The dedicated XML format can be created by adding a transform after the export is done.

No comments: