Can you post/share a document that shows the problem?
Thanks for your response.I tried to attach a document..but i couldn't..How can I attach a document here?
attaching documents is not possible / allowed.
Upload your files to a service like Dropbox and post the download link here.
Thanks for your guidance.I have uploaded the document and the link is
Link: https://www.dropbox.com/s/ht5wb3vxrpe0b7h/Sample1.idml?dl=0https://www.google.com/url?q=https://www.dropbox.com/s/ht5wb3vxrpe0b7h/Sample1.idml?dl%3D0 &sa=D&source=hangouts&ust=1525856229236000&usg=AFQjCNHBYFrOvOtnnbg69ciMCu-jdPtuuA
In this document I have placed two xml elements.Please do run the script by selecting the frame.
For the first element I am able to get the family id but for the second one I get "Object is invalid"error.How can I get the attribute value here.
I think I have found the problem when running your code this is the result :
Text Frame one ( with the URI looking contents) has 4 attributes - COTYPE, family_id, sub_Families, TBGUID
Text Frame two ( with the random text) has only 2 attributes - COTYPE, TBGUID
Therefore the code is failing on the itemByName ("family_id"); part because there is no "family_id" attribute to get.
The reason for this appears to be the structure of your XML in the document.
For text frame one it is a direct descendant of the "product_family" tag, (
text frame two is a child of a direct descendant of the "product_family" tag.
To fix the code to work for the second text frame you need to add an extra ".parent" so you would have.
mySel=app.selection; var famid= mySel.associatedXMLElement.parent.parent.xmlAttributes.itemByName("family_id").value; alert(famid);
obviously this would then cause the first frame to be incorrect, so you need to somehow detect if you are at the correct level, I would suggest doing something like
var parentNode = mySel.associatedXMLElement.parent
var nodeValue = parentNode.xmlAttributes.itemByName("family_id")
if ( !nodeValue.isValid)
nodeValue = parentNode.parent.xmlAttributes.itemByName("family_id");
nodeValue = nodeValue.value;
alert ( nodeValue);
Hope this helps
I got it.Its working fine.Now I am able to get the ids.Thank you so much for your guidance..