Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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, "™" (Trademark) or " " (nonbreaking space) but the ampersand has not been one of them.
Copy link to clipboard
Copied
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);
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more