Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 12, 2012 Oct 12, 2012

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?

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 12, 2012 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2012 Oct 22, 2012
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines