1

I am working on IDML files which are used by InDesign. I am facing a problem in inserting a special instruction. I need to embed RightIndentTab with IDML file. The unicode for the same is U+0008. When I try to add that it throws error as this unicode is not supported in XML specs.

I looked more into it and IDML has a special Processing Instruction which can be inserted it looks like now the problem is when I add this it introduces a line break before the RightIndent symbol. On debugging I found that the content element looks like

             <Content>
                <?ACE 8?>9731396</Content>

It is an XElement and I see \r\n when I call ToString() on it. I also tried using XmlWriter.

What I would like is an XElement object which looks like

             <Content><?ACE 8?>9731396</Content>

Thanks in advanced!

Rajat Mehta
  • 201
  • 3
  • 14

1 Answers1

1

I've encountered exactly the same problem adding processing instructions to IDML, using .NET. Even with significant whitespace turned off I got a line break that InDesign treats as part of the text.

The only solution I have found is to save the file as XML, then open it as a text document and use a regular expression to replace >\r\n<? with just ><?. It's ugly and kludgy, but it does work - I don't have the regex to hand but you should be able to figure it out fairly quickly.

I've never had any problems adding unicode chars to XML, though. I would just use &#x0008; and also set the XmlWriter encoding to use unicode. See here for an example: http://bytes.com/topic/net/answers/176665-how-write-unicode-using-xmlwriter which recommends:

XmlTextWriter myWriter = new XmlTextWriter( fileStream,
new System.Text.UnicodeEncoding( false, false) );
Jude Fisher
  • 11,138
  • 7
  • 48
  • 91
  • Thanks for the reply. That is of course one solution where you process the file again after dumping the XML on file system. Is it any way we can do it before we put it on the file system? – Rajat Mehta Nov 16 '12 at 17:19
  • Not once you've got the processing instruction in place. The fault is InDesign's really - it ought not to represent the space between the opening `` tag and the processing instruction as significant, but obviously their parser treats everything inside the `` node as a string, rather than as XML. Your best bet will be to use the XmlTextWriter in Unicode mode, which should allow you to insert hex Unicode characters such as `` You will need to make sure the document is saving as UTF-16 (not UTF-8) - then I think your special character should work. – Jude Fisher Nov 16 '12 at 18:06
  • As far as I know it won't work as its a BACKSPACE character which in XML specs is a not supported character. That might be the reason IDML introduced this special XML processing instruction to represent them as a replacement. – Rajat Mehta Nov 16 '12 at 19:37
  • Ah, possibly - I didn't realise it was specifically excluded . Probably best to go with post-processing then. Hope it works for you... – Jude Fisher Nov 17 '12 at 09:18