Copy link to clipboard
Copied
I have fetched the xml content having bullet points. When I have fetched the xml value then it get displaced as an •.And I have used the following code to get the content of XML. How can I replace this particular special character to bullet point?
if(inputXML.exists == true) {
inputXML.open('r');
var text = inputXML.read();
inputXML.close();
var content = new XML(text);
var elements = content.xpath("//CDATA");
for(var n = 0; n < elements.length(); n++){
if(elements[n].parent()["@"+attribute].toString() == id){
CDATA.push(elements[n].toString());
// alert(elements[n].toString())
}
}
}
So as I suspected this is an encoding issue. Add the following line after the open method call in your method getCDATAWithID
inputXML.encoding = "UTF-8";
This fixes it for me
-Manan
Your particular problem with bullets sounds like the file is read with the wrong encoding.
File.open does not know about XML, so it ignores the encoding= in the XML declaration, instead it just has a limited peek (some few characters) into the file when it has to guess the applied encoding.
Set inputXML.encoding = "UTF-8" before your open might get you further.
The rest of above script is a futile attempt to deal with all those CDATA - better read up the basics of XML, CDATA is separate concept an
...Copy link to clipboard
Copied
Please sbare the xml file. I think this might be related to encoding of the file object you create, but can't be sure unless we test it.
-Manan
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You have pasted incomplete code that does not even execute and errors out. The definition of the variables used is missing, how can someone guess then what results you get and how to test.
Specifically the variables inputXML, CDATA, attribute, id have missing definitions, out of which CDATA, attribute, id would be needed to atleast understand what the problem is.
-Manan
Copy link to clipboard
Copied
From the previous forum suggestion, I had fetched the XML content. But in that, I'm facing an issue. In the XML there are some special characters while reading the content the special character values like (•,') are replaced by (•, ’). And for this, I have attached the XML, INDD document, and script which I have been used for getting the XML contents.
https://1drv.ms/u/s!AvQ7CeTqFL3EiVuJOhiPk_Ha4Kqj
Copy link to clipboard
Copied
So as I suspected this is an encoding issue. Add the following line after the open method call in your method getCDATAWithID
inputXML.encoding = "UTF-8";
This fixes it for me
-Manan
Copy link to clipboard
Copied
Your particular problem with bullets sounds like the file is read with the wrong encoding.
File.open does not know about XML, so it ignores the encoding= in the XML declaration, instead it just has a limited peek (some few characters) into the file when it has to guess the applied encoding.
Set inputXML.encoding = "UTF-8" before your open might get you further.
The rest of above script is a futile attempt to deal with all those CDATA - better read up the basics of XML, CDATA is separate concept and not addressed like elements. You might get further with XPath expressions such as //*[contains(text(),'CDATA')] but I fear it will be more complicated.
Anyway, the file is already peppered with xmlns:aid and so forth that suggests it is intended for InDesign's document structure XML, a different beast than the ExtendScript xml technology that you're currently using. Please reconsider, this will be more things to learn but would also give you an XSLT processor on import.