Copy link to clipboard
Copied
Hi,
I tried to get particular attribute value of a element in xml.I used
var famid=mySel.associatedXMLElement.parent.xmlAttributes.itemByName("family_id").value;
This worked for me for some elements.But for some elements it returned 'Object is Invalid" error.What should be done to get the attribute value.?Please do guide on this..
Regards,
Revathi V
Hi,
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
Whereas
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 des
...Copy link to clipboard
Copied
HI,
Can you post/share a document that shows the problem?
Regards
Malcolm
Copy link to clipboard
Copied
Hi Malcolm,
Thanks for your response.I tried to attach a document..but i couldn't..How can I attach a document here?
Regards,
Revathi
Copy link to clipboard
Copied
Hi Revathi,
attaching documents is not possible / allowed.
Upload your files to a service like Dropbox and post the download link here.
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
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&sour...
In this document I have placed two xml elements.Please do run the script by selecting the frame.
mySel=app.selection[0];
var famid= mySel.associatedXMLElement.parent.xmlAttributes.itemByName("family_id").value;
alert(famid);
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.
Regards,
Revathi
Copy link to clipboard
Copied
Hi,
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
Whereas
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, (
whereas
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[0]; 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
mySel=app.selection[0];
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
Malcolm
Copy link to clipboard
Copied
Hi Malcolm,
I got it.Its working fine.Now I am able to get the ids.Thank you so much for your guidance..
Regards,
Revathi