Adding text to parentStory destroys XML element / JavaScript, InD CS4

Dear scripters,
I'm currently stuck with this problem:
- I'm writing text to text frames on a layout page
- while writing some characters/strings are XML tagged (I'm creating an element)
- I can do this only once, because adding more text after I have created an XML element destroys the link to the element
Here's my sample:
var MyBox = app.activeDocument.textFrames.add();
MyBox.geometricBounds = ["0pt","0pt", "200pt", "200pt"];
//Fill some content into the text frame
MyBox.parentStory.contents = "bla";
//create a xml element for some of the text
app.activeDocument.xmlElements.item(0).xmlElements.add("test1", MyBox.parentStory.characters.itemByRange(1, 2));
//so far so good...
//now some calculating
var result = "456";
//add result to the text frame
//doing this destroys the link to the existing xml element
MyBox.parentStory.contents += result;
//doing this creates a new xml element with the wrong characters selected and linked
app.activeDocument.xmlElements.item(0).xmlElements.add("test2" , MyBox.parentStory.characters.itemByRange(4, 2));
Can someone please help on?
Best regards,
TYPO

Hello Harbs,
thank you, it almost works now; the xml element brackets are not destroyed anymore.
The only problem I have now is that the second element becomes a  child of the first one.
How can I force each element to  be "independent"?
Here's the code:
var MyBox = app.activeDocument.textFrames.add();
MyBox.geometricBounds = ["0pt","0pt", "200pt", "200pt"];
var MyContent = "bla";
MyBox.parentStory.insertionPoints[-1].contents = MyContent;
MyBox.parentStory.characters.itemByRange(-1, -MyContent.length).select();
app.activeDocument.xmlElements.item(0).xmlElements.add("test1" ,app.activeDocument.selection[0]);
MyContent = "456";
MyBox.parentStory.insertionPoints[-1].contents = MyContent;
MyBox.parentStory.characters.itemByRange(-1, -MyContent.length).select();
app.activeDocument.xmlElements.item(0).xmlElements.add("test2" ,app.activeDocument.selection[0]);
Best regards,
TYPO

Similar Messages

  • How can I get the text value of an XML element  in MXML ?

    Hi,
    I have the following XML loaded into a variable of type XML :
    <properties>
         <comment>RIMpro Data Collector Configuration</comment>
         <entry key="server.pear.username"/>
         <entry key="server.apple.retry.times">5</entry>
         <entry key="rdc.proxy.host">http://192.168.1.2:8080</entry>
    /properties>
    I can easily get the key attribute displayed in a DataGridColumn by setting the dataProvider to my variable and the dataField to "@key".  But I do not know how to get the text value in a second column...  Is there a way or do I need to change my XML to something like this :
    <properties>
         <comment>RIMpro Data Collector Configuration</comment>
         <entry key="server.pear.username"/>
         <entry key="server.apple.retry.times" value="5"></entry>
         <entry key="rdc.proxy.host" value="http://192.168.1.2:8080"></entry>
    /properties>
    Many thanks in advance.
    Marc

    yes, you'd better modify your XML structure to fit the DataGrid internals.
    Since dataField pattern require each grid row item to have a named property to be displayed, otherwise you'll be forced to overcome this pattern using custom labelFunction for the particular column which will implement your custom actions on how to extract appropriate data for that column out of grid row item. It will be much more complicated than just rearranging your xml structure.

  • How to find associated text frame with XML element?

    Hello experts, I am new to InDesign CS SDK and have a question.
    I am building an Extension to import an XML document into an InDesign template. As the content in XML can be unpredictable, in the Extension, I want to loop through all the XML elements and make sure it has associated text frames, and if it doesn't, I want to create a text frame and set the content to the text frame.
    I think I figured out how to create a new text frame in page and set the content in the frame, but I am having difficulty finding an associated text frame for an XML element.
    If anyone has a sample code finding a text frame for an XML element, I appriciate it. Or if anyone can tell me what document I need to look, it will be great too.
    Thanks,

    Here's a code snipet with null checks removed:
    UID MyClassName::GetFrameForXMLElement(IIDXMLElement* inXMLElement)
        InterfacePtr< ITextModel > textModel( Utils< IXMLUtils >()->QueryTextModel( inXMLElement ) );
        InterfacePtr< IFrameList > frameList( textModel->QueryFrameList() );
        UID aFrameUID = frameList->GetNthFrameUID( 0 );
        return aFrameUID;

  • Delete xml element not used in document

    Hi,
    If you have a number of texts tagged with an xml element and then delete the text, the element still exist in the structure.
    You can see the element still connected to a text, by the blue diamond on the element symbol.
    But i want do delete the elements that have no connection to texts, but cant find the right property to look for.
    In Java script CS4.
    Anyone knows?
    /Mikael

    If the (text) element is unplaced, its parentStory will be an XmlStory rather than a Story.
    So try:
    var elements = app.activeDocument.xmlElements[0].xmlElements.everyItem().getElements();
    for (var i = elements.length - 1;i >= 0;i--){
        if(elements[i].parentStory.constructor.name === "XmlStory"){
            elements[i].remove();
    This is untested. If you have tagged graphics frames it will need to be modified to not error on those.
    Jeff

  • How to map more than one xml element with some Paragraph in a Text Frame

    Hi friends,
    I am new in InDesign Java Scripting and I have to place or map, more than one xml elements of different parents, into one textbox. Is it possible through JavaScript? Can anyone help me in this because I have no idea how it should work and it urgently required.
    Thanks in Advance

    I had answered to you already in your first post: the short answer is that it's not possible on the same text box unless you assign a common ancestor of these two "parents" item. That's not a question of scripting, it's the way Indesign handle the XML with the layout. Import a xml in Indesign and drop tags to page item. What you can do manually is quite representative of what can be done through scripting.
    If you assign this anscestor to the text frame, you have to expect that all text child items will be displayed in the text frame (including the text of all the child of the two "parents" and all the other parents/childs that could be under the common ancestor). Having a XML that is designed for Indesign usage is pretty much inevitable if you are doing anything "serious".

  • How to insert Text physically to xml in xml Element

    hello friends,
    I am newb of jDom. i am trying to change xml "Element's"--->"Text". My xml is as follows .....
    <?xml version ="1.0">
    <Elements>
             <code>
                       <data>EE550</data>
             </code>
    </Elements> I am trying to replace that "<data>" by <data>AA550</data>
    my code is as below
                 SAXBuilder sb = new SAXBuilder();
                 Document doc = sb.build(new File("src/xml/M90EE.xml"));
                 Element element = doc.getRootElement();
                 List children = element.getChildren();
                 String key = (element.getChild("text").getChild("mkey").setText("AA550").getTextTrim());   System.out.println("mkey       :"+key);
    output:
    mkey   :AA550 but is it possible to change in the xml file phisically.
    thanQ
    Ajay

    hello Reegz,
    ThanQ so much for perfect solution....
    when i do like that it is actually adding text to the existing Element Text.. so i wrote as follows....
    SAXBuilder sb = new SAXBuilder();
    Document doc = sb.build(new File("src/xml/M90EE.xml"));
    *String skey = (element.getChild("text").getChild("mkey").removeContent().toString());*     //--------->step 1
    *String skey1 = (element.getChild("text").getChild("mkey").addContent("ISO9001").toString());* //-------->step 2     
    String rdmkey = (element.getChild("text").getChild("mkey").getTextTrim());
    XMLOutputter serializer = new XMLOutputter();
    String str = serializer.outputString(doc);
    FileWriter fr = new FileWriter("src/xml/M90EE.xml");
    fr.write(str);
    fr.flush();
    fr.close();Is there any other way to replace text in step1 and step2 other than above or will it be enough for multiuser programming. Because this application will be accessed by so many number of user's what do u sujjest.
    thanQ ...
    Han.

  • I need to find all XML elements and add a line break to the text of each of them

    I need to find all XML elements and add a line break to the text of each of them.
    Is this possible with a script?

    I need to go from this ...
    to this...
    but looking for the XML elements (not paragraphs) and then adding text ...
    Thanks for your attention !!!

  • Premiere Elements 7 crashes when clicking/adding text.

    First post after being an Adobe user for several years so I can't complain. :-) I purchased Premiere Elements 7 a couple months ago and it has worked very well.
    I am now having a problem when attempting to add text. I tried adding text to a new project and get the message, "Adobe Premiere Elements has encountered a problem and needs to close. We are sorry for the inconvenience."
    I then opened a finished project and clicked the text on the screen and got the same message. So it occurs when trying to add new text or editing existing text. I have tried everything outlined in a post on what to try when you are experiencing problems.
    The specs to my 2002 Sony VAIO are below. Yes, it is old, but has been a workhorse during the last several years producing literally hundreds of videos. Any help you can provide is much appreciated.
    Windows XP Service Pack 2
    P4 processor
    2 gigs of RAM
    PRE7 installed on C drive with 65 gigs free space
    2 TBs storage space
    NVIDIA GEFORCE 5200

    Sam,
    When something works one day, but not the next, I look for what has changed. More often, than not, it's some program updating. Windows is famous for this, but then you can't update Windows, so that might rule it out.
    First thing I'd look into would be Restore Points. I always run a Restore in Safe Mode, and when there is a problem, will go quite a ways back, then work up to the present.
    If none of this works, then the virus/Trojan problem might loom more likely. Many of these can reside in Restore Points. When removing one, turning the auto Restore function OFF is usually advised. If you can locate such a nasty, then Google it. Chances are good that Norton, or others, will have a step-by-step way to remove it. It also seems that about 60% of all sites try to upload something nowadays, and much of it is not good. If you suspect any sort of infection, run your virus/Trojan sweeps from Safe Mode too. It will be slower, but more likely to uncover some problem. AdAware Search & Destroy offers a free version, and I usually keep it around, though I have many others. It seems to discovery things, that most other programs miss, with few false-positives. Even though I keep Norton, SpySweeper and StopZilla up, except when I am actually editing, and there is no Internet interaction, I'll do a Norton sweep in Safe Mode about once a week, just to be sure. Unfortunately, evil lurks right outside our door and some of it is tough to stop, find and disarm. The most benign sites often have little payloads, that can cause problems, if left "untreated."
    Good luck,
    Hunt

  • XML element to wanted position in content text?

    Hi,
    I am using java's XML document builder (javax.xml.parsers.*)....
    is it possible to create XML element to wanted position in content text, such as:
    <mycontent>
    Here comes text <AndHereIsElementInWantedPosition ... /> and the normal text does continue.
    Here comes text (2) <AndHereIsElementInWantedPosition ... /> and the normal text (2) does continue.
    </mycontent>
    I see only Element::appendChild(), and Element::setTextContent() functions, but it seems it's not possible with those functions.
    and if it's possible, what functions I should use to read Elements & their position from content text? (Node class doesn't tell the position).

    is it possible to create XML element to wanted position in content textYes. Text is just another kind of node. You can interleave Elements with Text nodes. The Elements aren't 'inside' the text, they are beside it, as sibling nodes.
    I see only Element::appendChild(), and Element::setTextContent() functions, but it seems it's not possible with those functions.Should be. Just append children, Text nodes or Elements.
    and if it's possible, what functions I should use to read Elements & their position from content text?You don't. You read the child nodes from the parent element. Some of them will be Text nodes, some of them will be Elements.

  • XML Element of selected text

    Hi,
    I need to get the tag name of bold applied in InDesign document.  When finding bold contents in InDesign document using Find Options, its select bold contents with some hidden text (tags) as shown in the below image.  If i use "select in structure" of selected text, its select wrong element (parent of all selected elements).  I need to get the correct XML Element of selected text (Except hidden character).  How can i get the element of selected text??
    Can anyone help me.
    - Sudha K

    Hi,
    I need to get the tag name of bold applied in InDesign document.  When finding bold contents in InDesign document using Find Options, its select bold contents with some hidden text (tags) as shown in the below image.  If i use "select in structure" of selected text, its select wrong element (parent of all selected elements).  I need to get the correct XML Element of selected text (Except hidden character).  How can i get the element of selected text??
    Can anyone help me.
    - Sudha K

  • MDIS ValueX XML Structure, element TEXT not found in xml schema

    When you extract ECC Contract through MECCM using port ERP Contract Data Transmission, if your mapping isn't correct 2 exception types are created: StructuralX or ValueX (and ImportX but I haven't seen this type of exception yet).
    Anyone noticed that the structure of the XML messages are actually different? The XSD for structuralX files are the same as the files placed in the "ready" folder, where as the XSD for the valueX files are DIFFERENT, and contain a tag called <TEXT>.
    This raises an issue when we're trying to handle exceptions in Import Manager using the type Port.  We get error "Logon Error: Source file does not conform to XML Schema. Element <TEXT> not found in xml schema".
    We can process exceptions in the structuralX folder, but not in the valuex folder because the xml file structure in the valuex folder is different.
    Just wondering if anyone else has had this issue or has resolved it.  We will open message with SAP.
    Thanks.

    Hello
    What is your MDM version ?
    this issue happened in old MDM 7.1 versions but was fixed in SP-2 unless you mapped Clone fields and in this case the fix is a bit later.
    In MDM 7.1 the latest builds of SP-2 and SP-3 should have the fix for all issues. But if you use MDM 5.5 then some issues regarding XSD conversion for exception where not addressed due to technical issues.
    The workaround for MDM 5.5 (If you use a late build of SP-6 Patch-4 or SP-6 Patch-5)  is to use the original file to fix the exception and not the file in the exception folder.
    Please notice that when you have Structural exception then all the Source XML file will go to the Exception folder.
    But in case of Value Exception - The source XML file will be dropped in the archive folder and another XML file containing VXR's (Virtual Extended Records) will be dropped in the exception folder, Therefore will have a different structure.
    Hope it helps.
    Thanks.
    Best Regards.
    Yaron.

  • Adding text to indesign pages with specific font ,size,and color using javascript

    Hello,
    Using javascript i am able to add some text to each page of an indesign file.
    myNewText = "SOME TEXT"
    myTextFrame = myPage.textFrames.item(0);
    tempframe = myTextFrame.contents;
    myTextFrame.contents =  myNewText + tempframe ;
    But i want to specify the font used,size and color for that text.
    When i try the code mentioned in indesign javascript scripting guide
    myNewText .appliedFont = app.fonts.item("Times New Roman");
    myNewText .fontStyle = "Bold";
    nothing gets changed and font family already used stays the same.
    How can i do that only for the added text and not for the whole content?I dont want to add the text to a new text frame I want to append it to the existing text frame.
    And is there a way to specify font size too?
    thank you

    There's a mixup going on here. Let's see if we can sort out some of it
    at least.
    If you just want to add new text to an already existing text frame,
    that's easy:
    myTextFrame.contents += "Hello";
    But if you want the new text to have unique formatting, it's a little
    more complicated.
    There are two simple ways to do it, I think:
    1. Create a temporary text frame, as you have done, and add the text,
    and format everything in there. Then move() that formatted text to the
    end of myTextFrame and delete the temporary frame:
    tempFrame = app.activeDocument.textFrames.add();
    tempFrame.contents = "New Text";
    tempFrame.paragraphs[0].appliedFont = app.fonts.itemByName("Times New
    Roman"); // etc...
    tempFrame.paragraphs[0].move(myTextFrame.insertionPoints[-1],
    LocationOptions.AFTER);
    tempFrame.remove();
    2. The other option, is to add the text directly to your textFrame. But
    if you want to format only that text, you have to store where the text
    started:
    myTextFrame = app.selection[0];
    firstInsertionPoint = myTextFrame.insertionPoints[-1].index;
    myTextFrame.contents += "New Text";
    myAddedText =
    myTextFrame.characters.itemByRange(myTextFrame.insertionPoints[firstInsertionPoint],
    myTextFrame.insertionPoints[-1]);
    myAddedText.appliedFont = app.fonts.itemByName("Trajan Pro"); // etc.
    What you've done in your sample script, however, is to try to apply a
    font to a simple JavaScript string. It won't work, but the way you did
    it, it won't throw an error either, because in fact you've created a new
    property of your string. (myString = "Hello"; myString.appliedFont =
    "Times"; // myString now has a Javascript property called appliedFont --
    but that's nothing to do with InDesign!)
    HTH,
    Ariel

  • Counting xml elements using javascript

    How can I count the number of certain xml elements inside the xml file that import.
    Example xml:
    <list>
         <product>
              <name>Product_01</name>
              <detail>info here</detail>
         </product>
         <product>
              <name>Product_02</name>
              <detail>info here</detail>
         </product>
         <product>
              <name>Product_03</name>
              <detail>info here</detail>
         </product>
    </list>
    I would like to count the number of product -elements in this example xml.
    I'm using javascript for scripting.
    Thanks.

    #target indesign
    #include "/Applications/Adobe InDesign CS3/Scripts/Xml Rules/glue code.jsx"
    var myDocument = app.activeDocument;
    var myCounter = 0;
    var myRuleSet = new Array (new ProcessProduct);
    with(myDocument){
        var elements = xmlElements;
        __processRuleSet(elements.item(0), myRuleSet);
    alert("Found " + myCounter + " product elements");
    function ProcessProduct(){
        this.name = "ProcessProduct";
        this.xpath = "//product";   
        this.apply = function(myElement, myRuleProcessor){
            with(myElement){
                myCounter++;
        return true;

  • How to create a xml element for Text with Java?

    Hi @ all,
    I want to tag a part of a text with Java.
    Like the InDesign function "Tag für Text" (maybe "tag for text" in english)
    Is there a way to tag text with Java?
    I tried to autoTag and to markup the text with an existing xml, but only got IdsExceptions.
    here the code where to tag the text:
    XMLElement newXML = parentXML.addXMLElement(VariableTypeUtils.createString("newXML"),OptArg.noVariableType());
    Text[] texts = para.findText(OptArg.noBoolean());
    for (Text text : texts)
       //TODO tag text
    Exception throwing code:
    text.autoTag();
    text.markup(newXML);
    newXML.markup(VariableTypeUtils.createObject(text));

    This is not a Web Dynpro specific question. This forum is for Web Dynpro specifc development aspects. There are other forums for general ABAP development as well as other specific aspects of ABAP development.
    I strong suggest that you review the rules of engagement for forum involvement, Derek.  You have had multiple violations of the rules in the last week.

  • CS3 / javascript / Creating anchor frame and placing xml element

    Hi All,
    I have a problem with creating anchor frame, that is
    Actually i have created anchor frame, but it is not allowing to place the xml element, it shows "inline frame xml elements not allowed" some thing like this.
    I have handled anchor frame type is "custom" but it shows "inline frame".
    Any of you got better idea about this.
    regards,
    sudar.

    I believe this has to do with you doing a placeXML, where the XML contents does not match the tagged frames in the document.
    Again i'm not sure, but i dont think this has to do with what kind of frame you are placing into(inline or custom anchor) rather if your tagged frames and XML match up.
    Perhaps this link will help:
    http://forums.adobe.com/message/1111773

Maybe you are looking for

  • Multiple devices multiple users

    Hi, I'm unsure what to do here and can't really find a straight answer anywhere. I have 2 iPads, iPhone 4s all synced to icloud under my apple ID I use to purchase from iTunes (still on PC, haven't upgraded to Mac yet).  My wife has just got an iPhon

  • Spacing between components change due to screen resolution

    Hello All, I am using GridBagLayout for desiging a screen for my application. I had defined the spacing between each component and had run the application in my system. It is working fine. But if the same code is run from another system with a differ

  • Firefox sync did not work as expected

    I set up both computers [actually in the same room on different desks]. Same Password, same secret phrase. It said it was working ON both computers. but nothing happened.

  • Ie bug???

    I have a page that displays fine in firefox, but not in IE. In IE, it stretches the picture across the page. ( http://www.smsvb.net/school/index.html) I thought it was the way I'd structured the tables, but have checked those and can't find the probl

  • Using PSE13 as external editor with iPhoto w/MAC OS

    Upgraded from PSE12 to 13 and now unable to use PSE13 as an external editor with iPhoto on a MAC OS V 10.9.  Have reinstalled and no change.  Preferences in 13 differ from help for older versions.