Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Trying to update some scripts and I found a few things I don't recall reading in this thread:
In CS3 (and CS4) you get an error trying to create xml tags that already exist:
myDocument.xmlTags.add(sTag)
Error: A tag with that name already exists. Please choose a different name.
(while in CS2 the same code just returned the existing tag without an error)
xmlElement can have several parents. The parent propery is then returned as an array. The same goes for tags.
Having more than one element with the same name, and assuming that there is only one by using myElement.item(the duplicate name here) you seem to get a single xmlElement but it has for example several markupTags (markupTag can be an array in CS3 and later).
Copy link to clipboard
Copied
Andreas Jansson wrote:
Trying to update some scripts and I found a few things I don't recall reading in this thread:
1. Trying to create xmlTag that already exists raises error in CS3
In CS3 (and CS4) you get an error trying to create xml tags that already exist:
myDocument.xmlTags.add(sTag)
Error: A tag with that name already exists. Please choose a different name.(while in CS2 the same code just returned the existing tag without an error)
Don't "add" tag - just use it in taggin process:
With myXMLelem.XMLElements.Add("character")
Call .XMLAttributes.Add("type", "text")
.Contents = "empty paragraph" & vbCr
Call .XMLAttributes.Add("aid:cstyle", .Texts.Item(1).AppliedCharacterStyle.Name)
End With
or
With myTSRangeText.AssociatedXMLElements.Item(1).Parent.XMLElements.Add("character")
Call .Markup(myTSRangeText)
Call .XMLAttributes.Add("type", "text")
Call .XMLAttributes.Add("aid:cstyle", myTSRangeText.AppliedCharacterStyle.Name)
If .Parent.MarkupTag = "character" Then
Call .Move(idLocationOptions.idAfter, .Parent)
End If
End With
2. Several parents and markupTags for an xmlElement
xmlElement can have several parents. The parent propery is then returned as an array. The same goes for tags.
Having more than one element with the same name, and assuming that there is only one by using myElement.item(the duplicate name here) you seem to get a single xmlElement but it has for example several markupTags (markupTag can be an array in CS3 and later).
Few .parents ? Or you are talking about .AssociatedXMLElements collection for Text object ?
robin
www.adobescripts.com
Copy link to clipboard
Copied
No 1. I might want to create tags (in the tags palette), first, for one reason or another 🙂
That is, not in the immediate tagging process.
No matter the reason: there is an add method on the tags collection, and as I see it, it was changed ... and this is the place to record it.
No 2 is about having a reference to an xmlElement object in the structure (XML tree).
Also, I forgot to mention that I'm using javascript, so there might be differences in how the objects are returned.
To illustrate, here is a piece of my code. I have a reference to an xmlElement object in the tree. Let's call it elemToFind:
if(elemToFind.index.length>1){
// If elemToFind is not a single object, get its FIRST parent using [0], and go down again to get a SINGLE instance of the object instead.
elemToFind = elemToFind.parent[0].xmlElements.item(elemToFind.index[0]);
alertAndLog('The XML element "' + elemToFind.markupTag.name + '" exists more than once, under the same node.');
}
The elemToFind was set (as I wrote in the previous message) using the item() method of its parent.
If the XML structure looks like this:
Root
Sibling1
Sibling2
Sibling2
Sibling3
... then I experienced this problem when setting a reference to elemToFind = myParent.item('Sibling2')
Causing elemToFind to behave differently from CS2, where you automatically got a single object reference set to one of the "Sibling2" objects, the first I think.
As you see in the sample code elemToFind.parent is no longer a single object. Probably caused by the new nature of the object returned by xmlElement.item()
(I might also have got the mening of "several" wrong, sorry for the confusion. I meant >1).
Andreas