Markup Tag Access Not Allowed

I somehow need to set a variable to particular markup tags (and eventually particular markup tags of those markup tags). For now, I just don’t know enough to figure out how or why I can’t get access to the XML elements within a hierarchy tree in the structure of an InDesign CS2 document?

For instance, this line: set x to (markup tag whose name is equal to “aPNBox”) is coming up as access not allowed.

Can anyone help me figure out a way to assign a variable to every markup tag whose name is equal to “aPNBox”. I would be very grateful since this is driving me crazy :frowning:

Thanks,
Jeff

tell application "Adobe InDesign CS2"
	tell active document
		set theRoot to (item 1 of XML elements) -- the root element 
		set theElements to every XML element of theRoot
		repeat with x in theElements
			set x to (markup tag whose name is equal to "aPNBox")
		end repeat
	end tell
end tell

I was about to delete this post since I figured out a solution through much trial and error. It is very ugly but it seems to work.

I was having trouble deleting single aPNBox markup tags while leaving an aPNBox tag if it had a subtag called expirationdate.

For example: The structure tree originally looked like this:

  1. Root
  2.  idline
    
  3.  tagline
    
  4.  aPNBox
    
  5.  aPNBox
    
  6.  aPNBox
    
  7.  	expirationdate
    

The script then removed lines (4, 5) - the single aPNBox tags. Which is what I wanted, leaving a structure that looked like this:

  1. Root
  2.  idline
    
  3.  tagline
    
  4.  aPNBox
    
  5.  	expirationdate
    

I just wish I was able to follow the logic as to how my 3rd try block seems to take care of what was driving me crazy?

tell application "Adobe InDesign CS2"
	tell active document
		set theRoot to (item 1 of XML elements) -- the root element 
		set theElements to every XML element of theRoot
		repeat with x in theElements
			--this will untag any main tags not equal to aPNBox, idLine, or tagline
			if (name of markup tag of x is not "aPNBox") and (name of markup tag of x is not "idline") and (name of markup tag of x is not "tagline") and (name of markup tag of x is not "expirationdate") then tell x to untag
			--This will untag any single aPNBox tags.
			try
				set y to every XML element of x
				if (name of markup tag of x is equal to "aPNBox") then set theSubElements to every XML element of x
				repeat with y in theSubElements
					if (name of markup tag of y is not equal to "expirationdate") then untag y
				end repeat
			end try
			--This will untag any primary tags that are equal to aPNBox and have a subtag whose name is not "expirationdate" For example main tag equals aPNBox, and subtag equals aPNBox
			try
				set y to every XML element of x
				if (name of markup tag of x is equal to "aPNBox") then set theSubElements to every XML element of x
				repeat with y in theSubElements
				end repeat
				if (name of markup tag of y is equal to "expirationdate") then set theSubElements to every XML element of x
			on error
				try
					if (name of markup tag of x is not "idline") and (name of markup tag of x is not "tagline") and (name of markup tag of x is not "expirationdate") then tell x to untag
				end try
			end try
		end repeat
	end tell
end tell