Scripting Selective XML into a Single Text Frame? (& Some Other Stuff...)

Hi all, I could use some help (using version CS5.5).
I want to import (via Javascript) an XML file similar to this:
<movieRoot>
     <dvds>
          <movie>
               <title>2001: A Space Odyssey</title>
               <edition>Special Edition</edition>
               <features>NOTHING</features>
               <notes/>
          </movie>
          <movie>
               <title>Airplane!</title>
               <edition />
               <features>Extra Laughs</features>
               <notes/>
          </movie>
     </dvds>
</movieRoot>
I've been able to successfully do this, so no problem there.
Then I want to dump the child elements under the XML element "<dvds>" into a single text frame that spans 2 columns per page. That's easy enough too, except:
1) I want to filter the data so that empty elements or whose contents equal "NOTHING" do not appear.
2) I want to add static text title above some of the elements that remain (outside the XML proper).
3) Then I want to format the text (using Paragraph Styles).
Tall order, I know, but I'm keen on figuring it out. I initially created a document using placeholders and used the standard XML Import to populate it with data, which was filtered using scripts to remove extraneous placeholders and static text. It gave me the result I wanted, but as the XML will be regularly updated and since the "filtered" tags result in non-standard XML entries, it means starting over from scratch after every XML update. So I turned to scripting...
For point #1, I was able to filter properly using a recursive IF statement, tested here using message alerts:
I've included a bunch of variables for (hopefully) easier viewing.
var myXMLRoot = myDocument.xmlElements.item(0);  //movieRoot
var myXMLParent = myXMLRoot.xmlElements.item(0);  //dvds
var myXMLElement = myXMLParent.xmlElements.item(0);  //movie
var currElement = myXMLElement.xmlElements.item(0);  //title
for (i = 0; i < myXMLParent.xmlElements.length; i++)
    myXMLElement = myXMLParent.xmlElements.item(i);
    for (j = 0; j < myXMLElement.xmlElements.length; j++)
        currElement = myXMLElement.xmlElements.item(j);
        if (currElement.contents != "" && currElement.contents != "NOTHING")
            alert (currElement.markupTag.name + ": " + currElement.contents);
It worked great until I tried to get it into an existing text frame. Since I want all the info in one text frame, placexml was out of the question, and markup worked but overwrote XML tags -- such as assigning the entire text frame to <movie/title> when I wanted it assigned to <dvds> with <movie/title> tags nested within it.
If you can help me with anything, this is really where I need pointed in the right direction most. But if you're feeling generous or bored...
Then for points #2 and #3, I want to take what's left ("filtered" XML data) and add additional text and formatting wherever certain tags are found.
For example, applying the paragraph style "MovieTitles" for any text within <title></title> XML tags; or adding the phrase "Special Features" (with paragraph style "Headers") above any text marked with <features> tags, while the content within those <features> tags applies the paragraph style "NormalText."
I've got some of this worked out in pieces already, but it generally falls apart because I can't get the tag structure correct in the text frame. I can provide more info as requested. Any help would be mighty appreciated!
UPDATE: Surprisingly, I've actually had some good success this evening on solving most of these problems. I'll post my results once I've finished up just in case anyone else can be helped by what I've learned.
One question remains for the moment: I've inserted text within an XML element, but outside of XML tags (e.g., </title>EDITION:<edition>) using "insertTextAsContent":
[xmlElementHere].insertTextAsContent("EDITION:", XMLElementPosition.beforeElement); 
Does anyone know a good way to apply a paragraph style to that text without using a find & replace function later (after placing the XML into a text frame)?

As posted into the other thread:
Yes, each record will be in its own frame.
You can use one of a couple solutions to stitch (link) each frame to the other, delete all but the first page and the first merged record, then resize that first merge frame and reflow the entire document.
https://forums.adobe.com/thread/1341730?start=0&tstart=0
Please review this thread. There is a couple posts with a script and you would want the last version of that script. You would have to follow the directions, as well as add a column at the beginning of your data and fill it with consecutive numbers.
Alternatively, there is a free plug-in by Rohiko for stitching merge data frames together, then follow the process above to reflow the document.
https://www.rorohiko.com/wordpress/indesign-downloads/textstitch/
Mike

Similar Messages

  • How can a 2 column text frame be split into 2 separate text frames?

    Hi InDesigners,
    I have a 12 spread (22 page) document that was originally created with a single column primary text frame in CS6. It contains text and anchored images throughout the doc. (images are anchored to the text frame).
    My client now wants each page split into 2 columns, but the columns need to have different widths - the left column needs to be narrower than the right. Although I can create 2 columns in a single frame, it's not possible to adjust the column widths separately, so I need to get them into 2 separate frames.
    Is there a way to convert a 2 column text frame into 2 separate text frames, so I can resize the column widths invididually?
    kind regards,
    -c

    hi, Thanks for the replies,
    The doc size is 8.5"x11", with 1/2 " margins. I never mentioned anything about it being a book. (It's just a paper my client wrote and woud like a PDF of it). The reason for the uneven columns is he wants the images to be 4" wide. For some reason, he wasn't keen on just a single column with text wrapped around the pix. I proposed making a 3" left column threaded into a 4" right col with a .5" gutter between them and he wants it that way.
    Thank you both for your respones. I'll try the script
    -c

  • Apply different font styles in single text frame

    hi all
    how can i apply different font styles in a single text frame using indesign script ?
    for example :
    "dasdnasndasndlasndnasdlasdasdas"
    may i know is it possible to do that and how to do that ?
    thanks

    You can set (as well as read) every single property of any text range with scripts. This is javascript; it assumes you text cursor is inside a frame with some text.
    * Setting some specific characters to a color:
    app.selection[0].parentStory.characters.itemByRange(5,10).fillColor = "Red";
    * Change the font of words:
    app.selection[0].parentStory.words[3].appliedFont = "Arial\tBold";
    * .. or just the style:
    app.selection[0].parentStory.lines[2].fontStyle = "Italic";
    * .. or any other attribute (this one requires you to have at least 5 characters selected):
    app.selection[0].characters[5].underline = true;
    Of course these operations are not limited to something you select; they work the same with any text frames you can refer to.
    app.activeDocument.textFrames[1].paragraphs[2].appliedCharacterStyle = "charstyle";

  • Multiple columns within a single text frame

    Is it at all possible to make a single text frame containing first a single column followed by two columns?
    Why: I need to have my heading expanding across my two column body text. What's important is that I need the two column body text to automatically drop whenever I type (or paste) in more text in my heading. Like it would if the heading and body text was in a single column.
    My text frame options (I work in CS3) do not give me this option, I can only work in one "frame set". I have tried fixing this problem with combinations of tables, multiple text frames and text wrap, but nothing really works.

    Thank you Peter.
    Yes I did try it.
    InDesign CS3 just gives me this alert:
    I also tryed copying the files (HeadStraddler.jsx and HeadStraddler.indl) into a folder like you suggested.
    C:\Program Files\Adobe\Adobe InDesign CS3\Scripts\Scripts Panel\Version 4.0 Scripts\HeadStraddlerForCS2.
    But I just get the same alert.

  • Data merging: how to get multiple records in single text frame?

    Hi
    I'm experimenting with data merging in InDesign CS3. The biggest stumbling block I've come across is trying to get my records to flow as continuous text in a single text frame (which would, ideally, autoflow onto new pages in the document). The records vary considerably in length, and so I can't just create a standard text frame to repeat on the page.
    Perhaps data merging isn't the best way of doing this and I should be learning to script instead. I feel like I'm just one step away, though.
    Any suggestions would be appreciated.

    OK, new scenario now:
    Is it possible to set a text box to auto-resize to fit the content that comes in during the data merge?
    I have placed one of my data fields in a text box with a stroke and fill, and placed this as an anchored object in the main text box with the other fields. The problem is that the length of text in this field varies considerably, and I'd like the text to fit snugly within its box. Ideally this text box would not appear at all if the field is blank for a particular record.
    I hope I've explained all of that clearly enough. Any ideas?

  • Create a  continuous flow of records in a single text frame

    I've searched past posts and cannot find the answer (though I'm sure the questions been asked aplenty).
    I have an Excel file with Company names, addresses, telephone numbers, emails and websites, etc. which are to be placed in a directory. I can't extract each company's details and get get them to flow in a single text frame (instead each seems to extract into it's own frame).
    Can anyone tell me what to do, please. I've spent more than an hour looking at the forums and various tutorials, etc.
    Bongani

    It might help if you post what versions of InDesign and Excel that you use, what OS you are in, and what format the Excel file is (.xls, .xlsx, .txt, .rtf, etc.). Also, you said your data needs to be placed, but some people paste instead of place, so I thought I'd ask you to specify how you are getting your data into ID.
    EDIT: Are you getting a table, when you want a text frame? I only ask because a table can look like a bunch of separate text frames.

  • How do i pass selected value of JList in one frame to other frame?

    hai everybody,
    In my application where i m using swing as GUI in that i require selected value of Jlist in one frame to other frame ..
    Since i need the previous frame jlist selected value for my application.
    How this can be done
    Help me pa
    Thanx in advance

    You need to post your Short, Self-Contained, Compilable Example or SSCCE if you need further help.

  • I need in more lines of the Index some words in Bold text and some others in Kursiv text. How can i get it? It seems to me that either i can have all the Style in Bold Text or in Kursiv Text :(

    I need in more lines of the Index some words in Bold text and some others in Kursiv text. How can i get it? It seems to me that either I can edit a Style only in Bold Text or in Kursiv Text
    I make you an example to clear what I really need:
    Index
    Introduction
    I. Leonardo's Monnalisa
    II. Leonardo's Battaglia
    Bibliography
    Please HELP HELP HELP

    What version of Pages are you referring to?
    Basically if you are talking about the Table of Contents in Pages and want to have different character styles within paragraphs in the T.O.C. you will have to export the T.O.C. and bring it back in as text and change that.
    Peter

  • HT1338 After I installed OS X Mountain Lion system, I can't use my Safari to log into my online banking and some other websites which require passwords. Can some one please help?

    After I installed OS X Mountain Lion system, I can't use my Safari to log into my online banking and some other websites which require passwords. Can some one please help?

    It could be browser incompatibility or something else. When you say you can't log in, what happens? Is the bank website generating an error saying you're not using a supported browser? Does the login form for your bank account display as usual, but once you submit the form to log in it doesn't work? Give me a specific step-by-step of what you're doing, such as...
    1. I load bankofamerica.com
    2. I type in my login
    3. When I submit, the page does nothing
    Obviously that may not be your issue, but giving us details like that will help us come to a quicker conclusion.

  • How to give Bold style inside Single Text Frame

    Hi
    I created a text frame with some text in it. It comes in three paragraphs. First para is the title with two words and below two are small description. All the text is kept in single textframe and I need that to be in single frame only. NOW, I need to bold the first para that is the title with two words. How can I write the code to give bold style to the first paragraph inside that frame? Do I need to take different frame? I want all in single actually. Also I want the entire text frame to give my customized text color.
    Hoping a valuable suggestion
    Thanks in advance.
    Regards
    P

    Dave, Good questions(s)!!! Details below...
    It's CS2. I need to put some text in all (many) documents I work regularly. Instead of copying from the previous file or any other source, as the text is same for all, I thought of writing the script with the text itself. Running that will create text frame and write the text. Got almost but was unable to bold the title of the text which I mentioned earlier as a first paragraph with two words.
    Also I couldn't give the my color swatch to the text.
    Here is my script:
    var myTextFrame = app.activeWindow.activePage.textFrames.add()
    var myParagraph = myTextFrame.paragraphs.item(0)
    var myFont = app.fonts.item("Arial")
    myTextFrame.geometricBounds = ["11.2in", "6in","9.57in","0.5in"];
    myTextFrame.contents = "First Paragraph"
    myTextFrame.parentStory.insertionPoints.item(-1).contents = "\r This is Second paragraph.";
    myTextFrame.parentStory.insertionPoints.item(-2).contents = "\r\rHere comes the Third Paragraph with extra para space";
    myParagraph.parentStory.appliedFont = myFont
    myParagraph.parentStory.pointSize = 8
    myParagraph.paragraphs.item(-1).spaceAfter = "0.05in"
    myTextFrame.fit(FitOptions.frameToContent)
    Hope this answers all your questions. Waiting for valuable solution. Have another question will ask after I got this. For now, two questions 1) making bold first two words 2) font color

  • 1 XML node to many Text Frames

    In indesign is it possible to map the content of a single XML node element to multiple text frames within an Indesign document?
    I have data elements in my XML that I don't want to repeat but they have to appear in multiple places within my document.
    Is this possible? What's the trick?
    Thanks,
    Gordon

    I don't have it to test with, but might the Linked Stories feature in CS5.5 allow you to do this? Maybe that's worth a look. I don't know of a way to do it in CS5 or before.
    Jeff

  • How to get all xml tags in a text frame?

    I want to get all the xml tags of the text in a text frame. I had tried the following methods but always get the tag binding the frame itself. <br /><br />1) XMLReference objXMLRef = Utils<IXMLUtils>()->QueryXMLReferenceData(textModel, 1);<br /><br />2) XMLReference objXMLRef = Utils<IXMLUtils>()->GetStoryThreadXMLReference(textModel, textIndex);<br /><br />Thanks in advance.

    I would think if you intanciate the XMLReference and use IIDXMLElement GetChildCount / GetNthChild would do what you are looking for.
    Ian

  • Insert items from two different Multiple Select Lists into a single table

    I need help. I have a training tracking system that tracks the courses taken by employees.
    I have created two multiple select lists, one is SelectEmployees and the other is SelectCourses. I want to insert
    the selected item from those two multiple select lists into Training_Record table.
    Note, SelectEmployees" is from Employee table and SelectCourses is from Courses table. Those two table has no intersetion.
    Train_Record is the table that joins those two together.
    Please advice and your help is appreciate.

    Thank you for your help.
    I tried your code and changed the table/field name to my actual table/field name and the iitem name to actual item name.
    declare
    cursor c_Employees is
    select PERSONNEL_NEW.EMPLOYEEID from PERSONNEL_NEW where PERSONNEL_NEW.EMPLOYEEID in (:P15_SELECTEDEMP);
    cursor c_Courses is
    select COURSES.COURSE_ID from COURSES where COURSES.COURSE_ID in
    (:P15_SELECTEDCOUR);
    begin
    foreach :=r_employee in c_Employees loop
    foreach :=r_course in c_Courses loop
    insert
    into COPYOFTRAINREC ( EMPLOYEEID, COURSEID )
    values ( r_employee.EMPLOYEEID, r_course.COURSE_ID );
    end loop;
    end loop;
    end;
    I got error message as :
    ORA-06550: line 12, column 25: PLS-00103: Encountered the symbol "C_EMPLOYEES" when expecting one of the following: (
    Error
    OK

  • How to get  selected records from an ALV  Grid in some other internal table

    I am using a standard SAP program (RFKKMA02) in a Z program. Now i want to select some rows in ALV and after doing some modification, i want to store those records in some other internal table. I am not using OO concept.
    Thanks in advance.

    u create first internal table of structur of fields that u want to copy and then move taht values to internal table

  • Concatenating into a single text field multiple choices from a dialog window

    I present a user with a form which contans a list from where to chose a few items.
    I need to take what he puts in there, and convert it into a string to pass it to a query... They click to select, and click to deselect, and I have to show in the underlying form's parameter list the items he has chosen in this form:
    joe,frank,rizzo
    if he clicks again on rizzo, the list (and he can see it) would show:
    joe,frank
    Thats the first part. Now, I have to pass three or more of these strings to a library procedure to do 'recheck' or validation, against the same tables, etc,). I don't want to put the loop in the library... but if I have to, I can only bring a single variable text string into it. Which means, I have to move each of the various strings of choices into the variable which goes to the library procedure.
    Complex enough?
    I have about three days to figure it out.
    Summary: 1. Concatenating the choices.
    2. sending different values into the library procedure, using the same variable in the library procedure.
    Thanks in advance!
    Nick
    null

    Try something like:
    // Get field values
    var first_name = getField("FirstName").value;
    var middle_name = getField("MiddleName").value;
    var last_name = getField("LastName").value;
    // Build full_name string
    var full_name = "Mr. " + last_name + ", " + first_name + middle_name;
    // Set this field's value equal to full_name
    event.value = full_name;
    This is intended to be the custom calculation script fot the "FullName" field.
    Refinements might be to have the user specify the title (Mr, Mrs, Dr., etc.) and handle missing values properly, but this should get you started.
    If you will be doing much scripting, you should get the Acrobat JavaScript Reference.
    George

Maybe you are looking for

  • Need help with applescript and Xcode 4.3.2

    I'm trying to write my first application that will involve a GUI. I can code applescript using script editor with a bit of effort, but I'm want to have users input more than one piece of information in the pop up. So, I download xcode, create my firs

  • Alaska 4G data device type support, phones with 4G included?

    Today is the big day; VZW officially fired up 4G data in AK yet aside from a couple of blips over the past year logged on my phone which I assume were testing, the phone isn't indicating the presence of 4G data. Is the 4G access limited to non-teleph

  • Mapping confirmed Activity type

    Can anyone tell me how to map the confirmed activity type with material number to fetch material description from makt table ?

  • Scudmenu -- A dmenu script for use with systemd --user

    So a while ago I started using systemd --user to manage my session, and I was pretty happy with how it turned out. However, I use a tiling wm, and sometimes I just want to quickly start or stop something without opening a terminal (say I'm looking at

  • Searching files within folders

    Hi, lets say i have a directory in finder for example mac os>music>r&b albums>2008 if i am in the r&b albums directory, if i type 'usher' in the top right search box, surely it would make sense to only search the directory i am in (r&b albums) and an