Creating hyperlinks from XML (noob)
Copy link to clipboard
Copied
Hi,
I'm researching how to do this but thought I'd back it up with a question here.
My XML has hyperlinks within it which I'd like to be active links when the InDesign doc is exported as a PDF.
The XML currently looks like:
<ArticleTitle><a href='http://www.url.com/link.htm' >Text to become hyperlink</a></ArticleTitle>
When I import it as it stands, in InDesign it looks like:
<a href=’http://www.url.com/link.htm’ >Text to become hyperlink</a>
What steps should I add to my script to format this and create the appropriate hyperlinks?
The import script already has plenty of search & replace, mapping to styles and error catching so adding a bit more won't be an issue - knowing how best to do it is
Thanks very much in advance,
Simon.
Copy link to clipboard
Copied
1. By Using evaluate xpath expression, you can get the //a[@href] elements.
2. Iterate those elements.
3. Set hyperlink text source then add hyperlink to the source text using the attribute value.
Thanks,
Green4ever
Copy link to clipboard
Copied
Thanks for that. This will take me a while (inexperienced scripter...)
3. Setting the hyperlink as an attribute. Below is how I imagined the XML should be structured:
<ArticleTitle href="http://www.link.com">Text to be hyperlinked</ArticleTitle>
The above doesn't create a hyperlink, which I sort of expected it to.
I tried adding the hyperlink within InDesign and exporting the XML to see how it should be formatted but the hyperlink created in InDesign doesn't appear.
In the meantime, I'll continue to learn about xpath expressions...
Thanks again,
Simon.
Copy link to clipboard
Copied
Okay, still stuck here. I cannot find any reference for how to include the URL in an XML tag that carries through into InDesign. Do I need to script that so it grabs the attribue for an XML element and adds the URL to a hyperlink within InDesign?
I believe I can get the XML structured so the URL is an attribute rather than a seperate XML element. Otherwise I'll cross that bridge once I crack getting the hyperlink into InDesign.
Can anyone help or point me in the right direction?
Thanks,
Simon.

