Skip to main content
Participant
June 9, 2008
Question

Delete any level xml element or attribute

  • June 9, 2008
  • 4 replies
  • 524 views
Hi,

In Design CS2, How can i delete or untag all the id attributes from the entire xml and any level with javascript.

Is it possible ?

Thanks with Regards
Pramod Pant
This topic has been closed for replies.

4 replies

Participant
June 20, 2008
Hi Jongware

Again Thanks a ton this line is working fine

Pramod Pant
Participant
June 11, 2008
Hi,

Thanks a Lot.

I will try then will let u know.

Regards
Pramod
Jongware
Community Expert
Community Expert
June 9, 2008
By the way,

startAt.xmlElements.xmlAttributes.everyItem().remove();


-- not sure if "everyitem" works with CS2. I've been in '3 for quite a while and skipped the previous incarnation. If it doesn't, iterate manually:

{

for (var j=startAt.xmlElements.xmlAttributes.length-1; j>=0; j--)
startAt.xmlElements.xmlAttributes.remove();
}


after the "if .."
Jongware
Community Expert
Community Expert
June 9, 2008
It just needs a little recursion. I wrote this

removeTags (app.activeDocument);


function removeTags (startAt)
{
for (var i=startAt.xmlElements.length-1; i>=0; i--)
{
if (startAt.xmlElements.xmlElements.length > 0)
removeTags (startAt.xmlElements);
startAt.xmlElements.untag();
}
}

in 2 minutes, found out that untag() already untags everything
i including
its sub-elements, then re-read your post. Ah ... just the attributes... Oh well. How about this:

removeTags (app.activeDocument);


function removeTags (startAt)
{
for (var i=startAt.xmlElements.length-1; i>=0; i--)
{
if (startAt.xmlElements.xmlAttributes.length > 0)
startAt.xmlElements.xmlAttributes.everyItem().remove();
removeTags (startAt.xmlElements);
}
}