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

How to delete xml content without deleting the content of the object?

Participant ,
Dec 01, 2014 Dec 01, 2014

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

TOPICS
Scripting
1.3K
Translate
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 ,
Dec 03, 2014 Dec 03, 2014

Does no one have a solution to this? I'm frustrated 😕

Translate
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
Explorer ,
Dec 05, 2014 Dec 05, 2014

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

Translate
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 ,
Dec 05, 2014 Dec 05, 2014

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);

}

Translate
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
Enthusiast ,
Dec 08, 2014 Dec 08, 2014

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

Translate
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 ,
Dec 08, 2014 Dec 08, 2014

Your original code works as you describe for me (assuming text_area is set to the Root element).

Translate
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 ,
Dec 09, 2014 Dec 09, 2014

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

Translate
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 ,
Dec 12, 2014 Dec 12, 2014
LATEST

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!

Translate
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