Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Getting XML attribute value and assigning link

Contributor ,
Feb 19, 2020 Feb 19, 2020

Hi,

I tried to get particular attribute value of a element in xml.I used                                                                var description=mySel.associatedXMLElement.parent.xmlAttributes.itemByName("descriptions").value  

. It returned 'Object is Invalid" error.What should be done to get the attribute value and to assign the link.?Please do guide on this..

TOPICS
Scripting
576
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2020 Feb 19, 2020

Can you share the screenshot of your document showing the document structure xml. I have been able to get your code working in my sample document. See it working for me in the screengrab using the following link

https://www.dropbox.com/s/t7txt0wbavc1cpw/screen%20recording%202020-02-20%20at%2010.18.54%20am.mov?d...

 

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 19, 2020 Feb 19, 2020

Hi Manan Joshi,

Thanks for your response. I have attached the screenshot of  document xml structure.

In the below screenshot the attribute description_link carries a hyperlink need to apply for attribute description content.

Please guide me to complete this...

Screenshot.png

 

Thanks,

Jothi

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2020 Feb 19, 2020

Hi Jothi,

 

What is your mySel object refering to, i can't see any selection in the screenshot you gave. Also i am unable to see any attribute named descriptions in the screenshot. Maybe you have text as selection, in that case you may try the following code

var description=app.selection[0].associatedXMLElements[0].parent.xmlAttributes.itemByName("descriptions").value  

 

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 20, 2020 Feb 20, 2020

Sorry for inconvience., I have attached another screenshot with highlight marks. please do refer that

 

Capture.PNG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2020 Feb 20, 2020

In the latest screenshot that you shared, the descriptions and descriptions_link are not attributes but xmlelements. The attributes are shown with a dot in front like attribute_id in your screenshot. Your structure does not match with your code nor did you explain what is in the mySel object. unless we know from object are trying to process its difficult to help you. Did you try my latest code?

 

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 20, 2020 Feb 20, 2020
LATEST

Yes! I have tried, but it shows an error message. I have uploaded the document to know the structure of xml and the link is

https://www.dropbox.com/preview/Sample/Sample.idml?role=personal

In this document I have placed two xml elements. descriptions and descriptions_link, where descriptions_link carries a link www.yahoo.com and description contains a some text. What i need is to apply the description_link to description texts using script. I have attached my expected output.

 Capture1.PNG

Regards,

Jothi

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines