×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Indesign CS5 - Import XML Using AppleScript

Indesign CS5 - Import XML Using AppleScript

Indesign CS5 - Import XML Using AppleScript

(OP)
Hi, new to everything about indesign but given task of trying to automate loading data from our database into indesign for our circular print.  I can export data from our database to xml and can manually import that data after setting up tags but now looking to automate.  I found some samples from indesign and will post below but having trouble understanding how to get it to load actual data from xml automatically.  It looks to create text box element but now how to add actual data?  I know manually I had to create placeholder text and tag but not sure how to do it in applescript or if I am even going about this the correct way?  

Here is the script and xml file and will attach link to picture of what it looks like in indesign.  THANKS!


--ImportXMLIntoSelectedElement.applescript
--An InDesign CS5.5 AppleScript
--
--Imports an XML file into the selected XML element.
main()
on main()
    mySetup()
    mySnippet()
    myTeardown()
end main
on mySetup()
    tell application "Adobe InDesign CS5.5"
        set myDocument to make document
        tell myDocument
            set myRootElement to XML element 1
            set myXMLTag to make XML tag with properties {name:"xml_element"}
            tell myRootElement
                set myXMLElement to make XML element with properties {markup tag:myXMLTag}
            end tell
            set myPage to page 1
            tell myPage
                set myTextFrame to make text frame with properties {geometric bounds:my myGetBounds(myDocument, myPage)}
            end tell
        end tell
    end tell
end mySetup
on mySnippet()
    tell application "Adobe InDesign CS5.5"
        set myDocument to document 1
        --<fragment>
        tell myDocument
            tell XML import preferences
                set import to selected to true
            end tell
            set myRootElement to XML element 1
            set myXMLElement to XML element 1 of myRootElement
            select myXMLElement
            --You'll have to fill in your own file path.
            import XML from "///Applications/tbl_BatchType.xml"
            --Place the XML element so that you can see the result.
            tell story 1
                place XML using myXMLElement
            end tell
        end tell
        --</fragment>
    end tell
end mySnippet
on myTeardown()
end myTeardown
on myGetBounds(myDocument, myPage)
    tell application "Adobe InDesign CS5.5"
        tell document preferences of myDocument
            set myPageWidth to page width
            set myPageHeight to page height
        end tell
        tell margin preferences of myPage
            if side of myPage is left hand then
                set myX2 to left
                set myX1 to right
            else
                set myX1 to left
                set myX2 to right
            end if
            set myY1 to top
            set myY2 to bottom
        end tell
        set myX2 to myPageWidth - myX2
        set myY2 to myPageHeight - myY2
        return {myY1, myX1, myY2, myX2}
    end tell
end myGetBounds


XML

<?xml version="1.0" encoding="UTF-8"?>
<X1>
<tbl>
<btDescription>TestDescription1</btDescription>
</tbl>
<tbl>
<btDescription>TestDescription2</btDescription>
</tbl>
<tbl>
<btDescription>TestDescription3</btDescription>
</tbl>
</X1>

Link to what it looks like in indesign.
http://www.general-trading.com/images/screenshot.jpg

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close