Copy link to clipboard
Copied
Howdy!
What if for some reason a person wants to actually make an XML file and stick some
<![CDATA[]]>
in it?
I looked through some manuals & OMV fairly quickly to discover no methods for that. Was wondering if there was some technique.
And, just as pointed out in the indesign forums, a string of "]]>" makes the script hang up and debugging have to be stopped with the final message "Cannot execute".
Sorry, my english isn't the best. I hope, I understand you right.
Try something like this:
var yourData = "Hi, Silly-V";
var aString = '<data>'+yourData+'</data>';
aString = aString.replace(/(\<data\>)/g,'$1<![CDATA[');
aString = aString.replace(/(\<\/data\>)/g,']]\>$1');
alert(aString);
Is this right for you?
If not, then show a few examples of what you have. And a couple of what you want.
Note: If I remember right, this code (or similar) was posted in the past by german ID scripters Martin Fischer a
...Copy link to clipboard
Copied
Silly-V schrieb:
… a string of "]]>" makes the script hang up and debugging have to be stopped with the final message "Cannot execute".
You want to work with
<![CDATA[]]>
in ESTK?
It seems to be a bug since CS5 and later.
Try to use:
]]\>
or:
\u005D]>
instead of:
]]>
Have fun
Copy link to clipboard
Copied
Okay, this is nice, thank you Mr Schubser. However, would it be possible to stick the CDATA right into an xml node? Because when I currently do this, it converts all the $<>" characters into xml escaped characters.
Copy link to clipboard
Copied
Sorry, my english isn't the best. I hope, I understand you right.
Try something like this:
var yourData = "Hi, Silly-V";
var aString = '<data>'+yourData+'</data>';
aString = aString.replace(/(\<data\>)/g,'$1<![CDATA[');
aString = aString.replace(/(\<\/data\>)/g,']]\>$1');
alert(aString);
Is this right for you?
If not, then show a few examples of what you have. And a couple of what you want.
Note: If I remember right, this code (or similar) was posted in the past by german ID scripters Martin Fischer and/or Uwe Laubender.
Copy link to clipboard
Copied
What wonderful help! Wünderbar! (right?)
I am now able to do the following:
function test(){
function stringXmlSafe(str){
str=str.toString();
str=str.replace(/&(?!(amp;|gt;|lt;|quot;|apos;))/g,"&");
str=str.replace(/</g,"<");
str=str.replace(/>/g,">");
str=str.replace(/'/g,"'");
str=str.replace(/"/g,""");
return str;
}
function wrapCDATA(str, propNm){
str = '<data>'+str+'</data>';
str = str.replace(/(\<data\>)/g, '<'+propNm+'><![CDATA[');
str = str.replace(/(\<\/data\>)/g,']]\>'+'</'+propNm+'>');
return XML(str);
}
var uiMenu=function(){
var opts={
string: stringXmlSafe,
cdata: wrapCDATA,
getOpt: function(grp){
for(var i=0; i<grp.children.length; i++){
if(grp.children.value==true){
return grp.children.text;
}
}
},
};
var w=new Window("dialog");
var fileNmG=w.add('group'); fileNmG.orientation='column';
var fileNmH=fileNmG.add('statictext',undefined,"File Name:");
var fileNm=fileNmG.add('edittext',undefined,"MyXMLfile"); fileNm.characters=22;
var elemP=w.add('panel');
var elem1H=elemP.add('statictext',undefined,'Element 1');
var elem1=elemP.add('edittext',undefined,''); elem1.characters=22;
var elem1OptG=elemP.add('group');
elem1OptG.add('radiobutton',undefined,"string"); elem1OptG.children[0].value=true;
elem1OptG.add('radiobutton',undefined,"cdata");
var elem1Sep=elemP.add('panel'); elem1Sep.size=[200,2];
var elem2H=elemP.add('statictext',undefined,'Element 2');
var elem2=elemP.add('edittext',undefined,''); elem2.characters=22;
var elem2OptG=elemP.add('group');
elem2OptG.add('radiobutton',undefined,"string"); elem2OptG.children[0].value=true;
elem2OptG.add('radiobutton',undefined,"cdata");
var elem2Sep=elemP.add('panel'); elem2Sep.size=[200,2];
var writeBtn=w.add('button',undefined,"Write XML");
var okBtn=w.add('button',undefined,"Ok");
okBtn.onClick=function(){
w.close();
}
writeBtn.onClick=function(){
var dir=Folder.selectDialog("Where?");
if(dir!=null){
try{
XML.prettyIndent=4;
var xmlBody=new XML('<root></root>');
var el1='elem1'; // property name
xmlBody[el1]=opts[opts.getOpt(elem1OptG)](elem1.text, el1); xmlBody[el1].@order=1;
var el2='elem2';
xmlBody[el2]=opts[opts.getOpt(elem2OptG)](elem2.text, el2); xmlBody[el2].@order=2;
var myXMLFile=File(dir+"/"+fileNm.text+".xml");
myXMLFile.open('w');
myXMLFile.write('<?xml version="1.0"?>\r'+xmlBody);
myXMLFile.close();
alert("Successfully saved "+decodeURI(myXMLFile));
} catch(e){
alert("Sorry, could not write "+decodeURI(myXMLFile)+" \nBecause of this: "+e);
}
}
}
w.show();
}();
}
test();
Copy link to clipboard
Copied
Glad i could help.
By the way – great stuff.
Or:
Wunderbar!
(wonderful, wonderfully, marvelous, delightful, delightfully, magically)
Copy link to clipboard
Copied
Oh I wish I could edit this, but stringXmlSafe is actually now supposed to be something which returns just the string since the invalid characters get escaped automatically when put into an xml object property vs using XML.appendChild('<custom>Blah &&&&</custom>')
Copy link to clipboard
Copied
Silly-V schrieb:
Oh I wish I could edit this, but …
Maybe you could upload a sample file. And in addition the result that you get. Third, show the result as you wish it to you.
Regards
pixxxelschubser
Copy link to clipboard
Copied
No, I have everything I need, I just did not see the [Edit] button on my message so I can change the script I've posted. Am I blind?
Copy link to clipboard
Copied
you can only edit your posts before someone replies to it.