Copy link to clipboard
Copied
Hey, with the following code I am marking up a page item and deleting it's xml content:
text_value = text_area.xmlElements.add('text', current)
text_value.contents = '';
current is the current app.selection. The code works, with one downside: It also deletes the content of my text frame in my document. I only want to delete the xml content. Is this somehow possible?
Thanks in advance!!
Regards
Fred
Copy link to clipboard
Copied
Does no one have a solution to this? I'm frustrated 😕
Copy link to clipboard
Copied
Hi,
1. Create a textframe and tag it with an xml Element (e.g. "myTextFrame")
2. Put some text in the textframe
3. Select the frame
4. run the script below
you added a new xml Element within the tagged frame and changed the content.
var curSel = app.selection[0];
var curXMLElement = curSel.associatedXMLElement;
var newXMLElement = curXMLElement.xmlElements.add('text');
newXMLElement.contents = "new Content";
Hope this makes sense.
Thanks Stefan
Copy link to clipboard
Copied
I can't do this. I need to delete the contents of my associated xml element, without deleting the content of the text-frame. I need A) the textframe associated with my xml Element and B) the contents inside the xml tag <text>asd</text> gone, like: <text></text>, without deleting the frame content.
I did a little workaround now, althought this solution is not really clean.
I save the contents of the textframe in another variable, delete this content, and then assign the content to the xml attribute where I need it. Of course the user has to close the document without saving then.
text_value = xmlElements.add('text', current);
var textContents = text_value.contents;
var textSize = current.parentStory.characters.item(0).pointSize;
text_value.contents = '';
with(text_value.xmlAttributes){
add('value', textContents);
}
Copy link to clipboard
Copied
Is this you asking?
var doc = app.activeDocument;
var text = doc.xmlElements.item(0).evaluateXPathExpression("//text");
for(var i =0;i<text.length;i++)
{
text.texts.everyItem().remove();
}
Regards,
Chinna
Copy link to clipboard
Copied
Your original code works as you describe for me (assuming text_area is set to the Root element).
Copy link to clipboard
Copied
Dear Fred,
Please use the below Code, this will helps you to achieve your target.
//============================== Script Starts ============================================//
var doc = app.documents[0];
//========================================================================//
/* Use Glue Code */
//==================================================================//
__RemoveXMLElments(doc);
function __RemoveXMLElments(doc)
{
var elementXpath = "//text";
var myRuleSet = new Array (new __RemoveXMLElments_XPath(elementXpath));
with(doc){
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
}
}
function __RemoveXMLElments_XPath (Txts)
{
this.name = "RemoveTexts";
this.xpath = Txts;
this.apply = function(myElement, myRuleProcessor){
with(myElement){
try{
var myCnts = myElement.texts.everyItem();
myCnts.remove();
}catch(e)
{
}
}
}
}
//============================== Script End============================================//
Thanks & Regards
T.R.Harihara SudhaN
Copy link to clipboard
Copied
Hey,
I didn't use xml rules yet, I will look into this topic and come back here as soon as I know more! Thank you for your help!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more