🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #14657

Re: [JS] How does the associated XMLElements property work?

#14657
From: Roberto Soto
Date: Tue, 27 Jan 2004 13:33
59 lines
3148 bytes
Hi pjredman

I am not sure what you wanna do, but I open my example, take a look.

Dim myInDesign As InDesign.Application
        Dim myDocument As InDesign.Document
        Dim myPage As InDesign.Page
        Dim myTextFrame As InDesign.TextFrame
        Dim myBounds() As Double = {10, 10, 20, 20}

Dim myTagName As String
        Dim myXMLTag As InDesign.XMLTag
        Dim myXMLElement As InDesign.XMLElement

myInDesign = CreateObject("InDesign.Application.CS")

If myInDesign.Documents.Count > 0 Then
            myDocument = myInDesign.ActiveDocument
            myPage = myDocument.Pages.Item(1)
            myTextFrame = myPage.TextFrames.Add
            myTextFrame.GeometricBounds = myBounds
            myTextFrame.Contents = "This is a first paragraph" + vbCr
            myTextFrame.Contents = myTextFrame.Contents & "This is a second paragraph"

myTagName = "TextFrame_1"
            myXMLTag = myDocument.XMLTags.Add(myTagName)
            myXMLElement = myDocument.XMLElements.Item("Root").XMLElements.Add(myXMLTag, myTextFrame)

myTagName = "Paragraph_1"
            myXMLTag = myDocument.XMLTags.Add(myTagName)
            myXMLElement = myDocument.XMLElements.Item("Root").XMLElements.Add(myXMLTag, myTextFrame.Paragraphs.Item(1))

myTagName = "Word_4_Paragraph_1"
            myXMLTag = myDocument.XMLTags.Add(myTagName)
            myXMLElement = myDocument.XMLElements.Item("Root").XMLElements.Add(myXMLTag, myTextFrame.Paragraphs.Item(1).words.item(4))

myTagName = "Word_5_Paragraph_1"
            myXMLTag = myDocument.XMLTags.Add(myTagName)
            myXMLElement = myDocument.XMLElements.Item("Root").XMLElements.Add(myXMLTag, myTextFrame.Paragraphs.Item(1).words.item(5))

Dim myParagraph As InDesign.Paragraph
            myParagraph = myTextFrame.Paragraphs.Item(1)

Dim i As Integer
            For i = 1 To myParagraph.AssociatedXMLElements.Count ' will be 2 items
                MsgBox(myParagraph.AssociatedXMLElements.Item(i).contents)
                ' i=1 -> all text
                ' i=2 -> text for the first paragraph
            Next

' If you need a reference to the tagged words inside the paragraph
            MsgBox(myParagraph.AssociatedXMLElements.Item(2).XMLElements.item(1).contents())
            MsgBox(myParagraph.AssociatedXMLElements.Item(2).XMLElements.item(2).contents())

Else
            MsgBox("No Document Found")
        End If

Roberto
Technical Details
Message-ID: <2ccf94be.3@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx
References: <2ccf94be.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,19f5d2c2e731681c
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2004-01-27 05:37:56 PST
From: "Roberto Soto" <roberto1soto@yahoo.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: Re: [JS] How does the associated XMLElements property work?
Message-ID: <2ccf94be.3@webx.la2eafNXanI>
Date: Tue, 27 Jan 2004 05:33:17 -0800
References: <2ccf94be.-1@webx.la2eafNXanI>
Lines: 69
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit