🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8650

Re: Make XML Tag

#8650
From: rajeevkumar
Date: Tue, 03 Oct 2006 06:17
108 lines
5065 bytes
Hi Pooja,

Please see the code below, it is a sample of XML.

=========================
tell document 1 of application "InDesign CS"
	set Publication to my getAttribute(XML element 1, "Article")
	set SectionNm to my getAttribute(XML element 1, "Section")
	set issueDate to my GetLevel3Contents("issueDate")
	set issueVolume to my GetLevel3Contents("issueVol")
	set issueNumber to my GetLevel3Contents("issueNum")
	set Storyelements to every XML element of XML element 1
	repeat with theElement in Storyelements
		set Category to ""
		set subSection to my getAttribute(theElement, "subSection")
		set thePage to my getPage(theElement)
		if name of (markup tag of every XML element of theElement) contains "Article" then
			try
				set subSection to (every XML attribute of theElement whose name = "subhed") as string
			end try
			set subElements to every XML element of theElement
			repeat with theSubElement in subElements
				tell theSubElement
					if "category" = (name of markup tag) then
						set Category to (text of theSubElement) as text
					else if "Article" = (name of markup tag) then
						set thePage to my getPage(theSubElement)
						my SetAttribute(theSubElement, "Category", Category)
						my SetAttribute(theSubElement, "subSection", subSection)
						my SetAttribute(theSubElement, "Publication", Publication)
						my SetAttribute(theSubElement, "Section", SectionNm)
						my SetAttribute(theSubElement, "issueDate", issueDate)
						my SetAttribute(theSubElement, "issueVol", issueVolume)
						my SetAttribute(theSubElement, "issueNum", issueNumber)
						my SetAttribute(theSubElement, "page", thePage)
					end if
				end tell
			end repeat
		else if name of (markup tag of theElement) = "Article" then
			my SetAttribute(theElement, "Category", Category)
			my SetAttribute(theElement, "subSection", subSection)
			my SetAttribute(theElement, "Publication", Publication)
			my SetAttribute(theElement, "Section", SectionNm)
			my SetAttribute(theElement, "issueDate", issueDate)
			my SetAttribute(theElement, "issueVol", issueVolume)
			my SetAttribute(theElement, "issueNum", issueNumber)
			my SetAttribute(theElement, "page", thePage)
		end if
	end repeat
end tell
on getAttribute(theElement, theAttributeName)
	tell document 1 of application "InDesign CS"
		if (count of every XML attribute of theElement) > 0 and (name of every XML attribute of theElement) contains theAttributeName then
			return value of XML attribute theAttributeName of theElement
		else
			return ""
		end if
	end tell
end getAttribute
on SetAttribute(theElement, AttributeName, AttributeValue)
	tell application "InDesign CS"
		tell theElement
			if AttributeValue = "" then
				if every XML attribute = {} or (name of every XML attribute) does not contain AttributeName then
					make new XML attribute with properties {name:AttributeName as string, value:AttributeValue as string}
				else
					set value of XML attribute AttributeName to (AttributeValue as string)
				end if
			end if
		end tell
	end tell
end SetAttribute
on GetLevel3Contents(elementName)
	tell document 1 of application "InDesign CS"
		set matchingElements to (every XML element of every XML element of XML element 1 whose name of markup tag = elementName)
		if matchingElements = {} then
			return (text of item 1 of matchingElements) as list
		else
			return ""
		end if
	end tell
end GetLevel3Contents
on getPage(theElement)
	tell document 1 of application "InDesign CS"
		set TextFrameLengths to length of text of every text frame of parent
		story of theElement
		set ElementPosition to story offset of theElement
		set TextFrameSubTotal to 0
		repeat with c from 1 to count of TextFrameLengths
			set TextFrameSubTotal to TextFrameSubTotal + (item c of TextFrameLengths)
			if TextFrameSubTotal = ElementPosition then exit repeat
		end repeat
		try
			return name of parent of text frame c of parent story of theElement
		on error
			return "error"
		end try
	end tell
end getPage

================

I am gettin problem on the below line can any one correct it.

		set TextFrameLengths to length of text of every text frame of parent
only on "length of text of"........

Thanks
Technical Details
Message-ID: <3bc1cf36.2@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!proxad.net!newsfeed1.ip.tiscali.net!tiscali!transit1.news.tiscali.nl!transit.news.xs4all.nl!xs4all!news2.euro.net!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!news.albasani.net!news.isoc.lu!webcrossing
References: <3bc1cf36.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,faea0353d31d4a46
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: rajeevkumar@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!proxad.net!newsfeed1.ip.tiscali.net!tiscali!transit1.news.tiscali.nl!transit.news.xs4all.nl!xs4all!news2.euro.net!213.132.189.2.MISMATCH!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!news.albasani.net!news.isoc.lu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: Make XML Tag
Message-ID: <3bc1cf36.2@webcrossing.la2eafNXanI>
Date: Mon, 2 Oct 2006 23:17:40 -0700
References: <3bc1cf36.-1@webcrossing.la2eafNXanI>
Lines: 116
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit