Skip to main content
Participant
October 12, 2012
Question

XML-error: Not well-formed (invalid token)

  • October 12, 2012
  • 2 replies
  • 2524 views

Hello,

I want a new XML structure in the Script from my InDesign CS6 (MAC 10.7.4) document. Here ist my little testscript:

     var doc = app.documents.item(0);

     var allStories = doc.stories;

   

    newXML = new XML('<root></root>');

    for(var i = 0; i < allStories.length; i++) {

        var curStory = allStories;

       

         for(var j = 0; j < curStory.textStyleRanges.length; j++) {

            var textStyleRange = curStory.textStyleRanges;

      

            alert(textStyleRange.contents);

            t = new XML('<content>' +textStyleRange.contents + '</content>');

            newXML.appendChild(t);

        }

    }

    alert(newXML);

The document has a text frame with the text, such as "C & A". When the script starts, it shows me the error message "XML-error: Not well-formed (invalid token)" on.

The problem with the "&" is. Probably also other Characters.

I think InDesign can automatically convert this into "&" or other entities, but how?

This topic has been closed for replies.

2 replies

Participant
October 22, 2012

I solved the Problem.

The line with

t = new XML('<content>' +textStyleRange.contents + '</content>');

is the Problem. textStyleRange.contents is not converted. The right way is here for the line:

t = new XML('<content></content>');

t.appendChild(textStyleRange.contents);

Known Participant
October 12, 2012

CORE_TEC_Germany,

are you sure the problem is with the &? Have you tried running a different file through this script without "&"? I've had to replace some characters in XML/ruby - generated TEXT STRINGS with an entity, for example, "&#x2122;" (Trademark) or "&#xa0;" (nonbreaking space) but the ampersand has not been one of them.