Get the original content from the XML in the InDesign Document

Explorer ,
Mar 25, 2022 Mar 25, 2022

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())
}
}
}

-Monisha
TOPICS
How to , Scripting

Views

143

Likes

Translate

Translate

Report

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

correct answers 2 Correct answers

Adobe Community Professional , Mar 29, 2022 Mar 29, 2022
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

Likes

Translate

Translate
Guide , Mar 29, 2022 Mar 29, 2022
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...

Likes

Translate

Translate
Adobe Community Professional ,
Mar 25, 2022 Mar 25, 2022

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

Likes

Translate

Translate

Report

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 ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

Hi @Manan Joshi 

 

Hereby I have attached the XML file and InDesign document for reference. 

-Monisha

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 28, 2022 Mar 28, 2022

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

 

Likes

Translate

Translate

Report

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 ,
Mar 28, 2022 Mar 28, 2022

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 

-Monisha

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 29, 2022 Mar 29, 2022

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

Likes

Translate

Translate

Report

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
Guide ,
Mar 29, 2022 Mar 29, 2022

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

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