Skip to main content
Inspiring
October 14, 2012
Question

Creating hyperlinks from XML (noob)

  • October 14, 2012
  • 1 reply
  • 3864 views

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>&lt;a href='http://www.url.com/link.htm' &gt;Text to become hyperlink&lt;/a&gt;</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.

This topic has been closed for replies.

1 reply

Green4ever
Inspiring
October 15, 2012

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

AngusdogAuthor
Inspiring
October 16, 2012

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.

AngusdogAuthor
Inspiring
October 18, 2012

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.