Skip to main content
karthikS
Inspiring
February 22, 2016
Answered

How to delete xml attributes by indesign file.

  • February 22, 2016
  • 1 reply
  • 1392 views

Dear friends,

I need to delete xml attributes only (Element "ul"), i have try to below coding and attached screenshot also, but i have doing  some mistake. i don't what i missing the below coding.

My coding in the below.

var elements = app.activeDocument.xmlElements[0].xmlAttributes.item["@new_class"] = "list-style-type:none";

    alert(elements.length);

    delete elements["@new_class"];

please suggest friends,

Advance Thanks,

This topic has been closed for replies.
Correct answer Ronald63

Hi,

Try this ...

var doc = app.activeDocument;

removeAttributes(doc,'ul','style','list-style-type:none');

function removeAttributes(source,element,attributename,attributevalue){

    for (var i = 0; i < source.xmlElements.length; i++){

            try{

                for(j=0; j<source.xmlElements.xmlAttributes.length; j++){

                    if(source.xmlElements.markupTag.name == element && source.xmlElements.xmlAttributes.name == attributename && source.xmlElements.xmlAttributes.value == attributevalue){

                        source.xmlElements.xmlAttributes.remove();

                    }

                }

            }catch(e){}

            removeAttributes(source.xmlElements,element,attributename,attributevalue);

    }

}

1 reply

Ronald63Correct answer
Legend
February 22, 2016

Hi,

Try this ...

var doc = app.activeDocument;

removeAttributes(doc,'ul','style','list-style-type:none');

function removeAttributes(source,element,attributename,attributevalue){

    for (var i = 0; i < source.xmlElements.length; i++){

            try{

                for(j=0; j<source.xmlElements.xmlAttributes.length; j++){

                    if(source.xmlElements.markupTag.name == element && source.xmlElements.xmlAttributes.name == attributename && source.xmlElements.xmlAttributes.value == attributevalue){

                        source.xmlElements.xmlAttributes.remove();

                    }

                }

            }catch(e){}

            removeAttributes(source.xmlElements,element,attributename,attributevalue);

    }

}

karthikS
karthikSAuthor
Inspiring
February 22, 2016

Dear Ronald,

Thanks you so match Ronald your script working super.

Again one more help Ronald,

How to added xml attributes in the xml element "ul" list? I have attached screenshot for your reference.

Step; 1

I want added in the following attribues - ul list

Advanced thanks Ronald friends,

Thanks,

Legend
February 22, 2016

Like this ...

var doc = app.activeDocument;

addAttributes(doc,'ul','class','ol_lower-alpha');

function addAttributes(source,element,attributename,attributevalue){

    for (var i = 0; i < source.xmlElements.length; i++){

            try{

                for(j=0; j<source.xmlElements.xmlAttributes.length; j++){

                    if(source.xmlElements.markupTag.name == element ){

                        source.xmlElements.xmlAttributes.add(attributename,attributevalue);

                    }

                }

            }catch(e){}

            addAttributes(source.xmlElements,element,attributename,attributevalue);

    }

}