26 February 2015
Comments: 0

Just stop DTD validation inside Adobe InDesign…

So you have to validate your InDesign XML structure with a DTD. A DTD consists in determining how your XML structure should look like. DTD is really rigid. I mean, consider DTD as the tough guy who will not make you enter the party if you don’t wear the right clothes. However, that rigidity within InDesign, really ? You have a cool creative application at hand and yet you have to work constrained? That doesn’t make sense at all.

So what…damn DTD validation ? Well why not postponing this at the time of your XML export whatever your structure is ?

This is a post dedicated to every InDesign user having to validate their XML structure against a DTD. Other may still have a look to the conclusion. First of all, we will introduce the concept of DTD. Second of all, we will show how to validate within InDesign. Last of all, we will expose an alternative to DTD validation.

A) DTD shortly

DTD stands for Document Type Definition. A DTD is a xml file that indicates what tags have to be used and how the xml should be structured. If your XML doesn’t comply, the validation will fail. In some workflows, validation is a critical part of the relationship between the authors and/or the publisher. Some DTDs are particularly famous such as the “DOCBOOK” DTD used in the publishing industry. However, everyone can build its own DTD.

<!ELEMENT ALIMENTS (ALIMENT+)>
<!ELEMENT ALIMENT (NOM, PERIODE, NUTRIMENTS)>
<!ELEMENT NOM (#PCDATA)>
<!ELEMENT PERIODE (#PCDATA)>
<!ELEMENT NUTRIMENTS (#PCDATA)>
<!ATTLIST ALIMENT TYPE (Fruit|Légume) #REQUIRED>

The DTD syntax above specifies that the XML root has to be tagged with “ALIMENTS”. This tag may contain one or several “ALIMENT” nodes. Etc.

B) DTD & InDesign

Let’s take a simple case. Here is simple table with fruits and vegetables data. We want to extract the table informations to XML with full respect to the DTD.

00001_aliments

Once we applied the specific text styles, we convert our table into text. If we try to tag the table contents without breaking the table, we will get InDesign Tables specific xml syntax we don’t want.

00002_conversion

Let’s load our DTD. Doing so, all needed XML tags will be automatically generated. Note that these tags are not editable as we are now working in a strict environment.

Locked tags with DTD

Now we are tagging the text contents using the “Map styles to tag” menu of the tags palette. That way any text with some specific style applied will be automatically tagged. If you have named your styles accordingly to tags, you can use the “Match with name” button.

00005_styles_aux_balises

After a bit of tweaking, we get a good structure. But is it a valid one ?

InDesign XML structure

To check the validity, click on the lightning icon. 

validationg InDesign Structure

Any problems ? InDesign let you know.

DTD validation issue

You can fix things by yourself or let InDesign do by clicking on the suggested correction.

Solution to DTD Validation

Repeat the fixes as many times as needed.

DTD Validation OK

At last, when everything is ok, InDesign displays “No errors found”. Now you can export your XML blindfully.

That clearly works but we had to break our tables to achieve the validation. What if we want to edit the table now ? What if we mistakenly closed the doc at this stage ? Isn’t that chimeric to validate while preserving our document layout ?

So what ? No validation ?

Well, rather than twisting our document, we are modifying the structure thus respecting the DTD at the export stage thanks to the XSLT technology.

C) Use XSL on export

Indeed, you can use a XSL file when exporting XML from your InDesign document structure. It’s good news because you don’t need to be obsessed with validation inside the document. You can keep on being intrepid with your layout and still comply to the DTD. Let’s go back to our table. Previously we had to deconstruct it to achieve validation. Not anymore !

00001_aliments

Once again, we will apply some basic tagging but that’s pretty all.

InDesign Table XML tagging

Of course a DTD validation at this stage would fail. But it’s not what we want to do. Let’s apply the following XSL.

Using XSLT to make our InDesign Structure compliant to our DTD

Now we will export our XML and call our XSL file.

Export XML from InDesign with XSLT

To check validity, we can use a specific software such as Oxygen XML. If everything is fine, validation is succesful.

Validating XML syntax with DTD

 

XML is Valid regarding to the DTD

What’s great here is that my table is still a native InDesign table that I can edit.

D) Conclusion

Of course, DTD validation inside InDesign remains a valid process. It’s particularly true in places where many operators may work. XSL is fine when the input is stable because you need to know what to work with.

But it some cases, I think XSL is a very valuable way of keeping a full creativity within InDesign and in the same time allows to export a XML file that will comply to the provided DTD.

So should you validate inside InDesign or use XSL to deal with that later ?
Well…it’s up to you 😉

Leave a Reply

Your email address will not be published. Required fields are marked *