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

Get the original content from the XML in the InDesign Document

Participant ,
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

245

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

Community Expert , 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

Votes

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

...

Votes

Translate

Translate
Community Expert ,
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

Votes

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
Participant ,
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

Votes

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
Community Expert ,
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

 

Votes

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
Participant ,
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

Votes

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
Community Expert ,
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

Votes

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.

Votes

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