Updating InDesign document with XML

New Here ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

Hi Professionals

 

I can able to update the xml of the whole indesign document if there is any changes in the xml using script...

Here, my doubt is shall i update only the modified contents of xml without disturbing 

the unmodified contents in the document.....

 

Thanks in Advance........

Regards,

-Parvathikannan.

TOPICS
How to, Scripting

Views

277

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 1 Correct Answer

Adobe Community Professional , Oct 28, 2020 Oct 28, 2020
To get any specific node & their attributes & CDATA, try like this or manipulate this: var allCDATA = []; var myXMLFile = File("C:/Users/r.sunil/Desktop/TestingCDATA/Test.xml"); myXMLFile.open('r'); var allElements = new XML(myXMLFile.read()); myXMLFile.close(); var allFeatureElements = allElements.xpath("//family_id"); for(var n = 0; n < allFeatureElements.length(); n++){ if(allFeatureElements.children().length() > 0){ getChildData(allFeatureElements); } } //============...

Likes

Translate

Translate
Adobe Community Professional ,
Oct 17, 2020 Oct 17, 2020

Copy link to clipboard

Copied

Hi Parvathikannan,

As per your post, I think your work flow is entirely XML based. As far as I can see it is better to import entire XML, because updating only changed XML structure will leave a margin for errors. To avoid that very small window for margin of error will be killed if you update entire XML.

 

But there is one more point if you update entire XML, you might have to put some more scripting if anything is getting changed(like paragraph style or character style) for those you need to do something, but after that no exception you will meet.

 

Best

Sunil 

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
New Here ,
Oct 18, 2020 Oct 18, 2020

Copy link to clipboard

Copied

Dear Sunil Yadav,

 

You're right, My work flow is based on XML and i already have the functionality to update the entire XML with some scripting files. I can understand your suggestion but, our client requirement is to update only the modified xml contents in the InDesign documents without disturbing other contents. Is there is any way to do it?????

 

Regards,

ParvathiKannan.

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 ,
Oct 19, 2020 Oct 19, 2020

Copy link to clipboard

Copied

There are always a way out.

If you are able enough to find out which xml element is modified(I am unsure how are you finding those). Then exactly those xml elements you can update in InDesign Files.

 

Sunil

 

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
New Here ,
Oct 25, 2020 Oct 25, 2020

Copy link to clipboard

Copied

Sunil, I'm Searching to find those modified contents, but i'm unable to do that.

If i'm able to get the family attribute id value then, there is a chance to get the elements value of the particular attribute it seems....

Is this possible?????????

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 ,
Oct 26, 2020 Oct 26, 2020

Copy link to clipboard

Copied

I also tried but I couldn't.

If you find anyway to do that please do let me know. Track changes might be the option to find modified contents.

But for updating XML is concerned, I think you should update entire XML.

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
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Dear Sunil,

 

Araised an doubt.......

I can able to fetch all the family_id value in XML....

By using that Family_id value shall i able to get the atrribute and the CDATA values that belong to that particular family_id. Is this possible????

 

Thanks,

ParvathiKannan.

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 ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Can you share some sample XML, then I might tell in better way.

 

Sunil

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 ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

To get any specific node & their attributes & CDATA, try like this or manipulate this:

var allCDATA = [];
var myXMLFile = File("C:/Users/r.sunil/Desktop/TestingCDATA/Test.xml");
myXMLFile.open('r');
var allElements = new XML(myXMLFile.read());
myXMLFile.close();
var allFeatureElements = allElements.xpath("//family_id");
for(var n = 0; n < allFeatureElements.length(); n++){
    if(allFeatureElements.children().length() > 0){
        getChildData(allFeatureElements);
        }
    }
//===================
function getChildData(nodeData){
    for(var c = 0; c < nodeData.children().length(); c++){
        if(nodeData.children()[c].toXMLString().toString().indexOf("<![CDATA[") == 0){
            alert(nodeData.children()[c].toString());
            allCDATA.push(nodeData.children()[c].toString());
            }
        if(nodeData.children()[c].children().length() > 0){
            getChildData(nodeData.children()[c]);
            }
        }
    }
alert(allCDATA);

Best

Sunil

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 ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

It is easily possible to update XML even node by node.

 

Best

Sunil

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
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

Dear Sunil,

 

I've attached the screenshot of my XML....

In the below XML each and every family has their own attribute and the element values. Now, by using family_id how do i get all the attribute node values....

Another thing is in the XML you can see the specs_type which has two atrribute titles and description, I need to get the CDATA values individually. But, now i'm getting both the title and description CDATA values together. How to get the CDATA values seprately????

 

ParvathiKannan_0-1603946315550.png

 

Thanks,

ParvathiKannan.

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
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

And same way i know that node by node update process is possible...

If i need to update an single node of an XML is possible?????

 

Thanks,

-ParvathiKannan.

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
New Here ,
Oct 28, 2020 Oct 28, 2020

Copy link to clipboard

Copied

I've attached the sample XML in the below link. Kindly check it.

https://www.dropbox.com/s/pbsrqs9rhjrxwxb/Sample.xml?dl=0

 

-ParvathiKannan.

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 ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

Updating a single node is also easily posible.

Now here we should understand: Whenever you need to store values separately, you should think on it & you can work on it.

I showed you a way to fetch all CDATA & already you know how to differentiate between differrent different node/s. SO accordingly you can create code logic wise.

 

Best

Sunil

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
New Here ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

LATEST

Yeah! I got it sunil. Thankyou!

 

Thanks,

ParvathiKannan.

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