Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Link to image in CDATA

Link to image in CDATA

In my XML-code I want to make a link to popup an image.

I have this code:
the data comes from this array:
 $files[] = array(
-and the XML-file:

$picfil = $dir."/".$name;
$file = fopen($dir."/".$name,"w");

$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<gpx>';
$xml .= '<metadata>';
$xml .= '<extensions>';
$xml .= '</extensions>';
$xml .= '</metadata>';                
for($i = 0; $i < sizeof($files); ++$i)      {
$xml .= '<wpt lat="' . $files[$i]['intLatitude'] .'" lon="' . $files[$i]['intLongitude'] .'">';  
$xml .= '<extensions>';            
$xml .= '<html>';
$xml .= '<![CDATA[<a href="#"><img src="'.parseToXML($files[$i]['filename']) .'"/></a>]]>';
$xml .= '</html>';
$xml .= '</extensions>';
$xml .= '</wpt>';  
$xml .= '</gpx>';

-and the function parseToXML

function parseToXML($htmlStr)  
return $xmlStr;  

I want to change the CDATA-code so I can open the image in an popup-window. The images is in different directories, so the must be a variable.


RE: Link to image in CDATA

[0] Let me set-aside any doubt in regard to the construction of $xml. I take it as correct to your satisfaction (including typos that may not exist in the script, $file at multiple places, or what to result of a pass-through of the function parseToXML().)

[1] >I want to change the CDATA-code so I can open the image in an popup-window.
As to this functionality, it belongs to html arena. It won't happen in the xml document as reflect in $xml.

[1.1] Having said that, you can extract the cdatasection as child of every possible <html> element. Put them all inside a html wrapper element, and then save it to a html file. In that case you can do the hyperlinking. (But then again just a remark: the href attribute is set to #. Hence, I don't see, a priori, the effect of clicking on the image bringing you to some other url. In any case, it doesn't matter and I leave it to you for further setup.)

[1.2] This is how it can be done as a quick sketch.

//etc etc in your script before the end

//now your desired output html file

$xpdoc=new DOMXpath($xdoc);

foreach ($anchors as $a) {
    $s.=$a->nodeValue."\n";  //no need to pass through any function like parseToXML


[1.3] Now you have a html file which has the rudimentary layout that gives you the desired hyperlinkage.

RE: Link to image in CDATA

I suggest i should replace my CDATA with something. Can you explain me?

If I replace my code in CDATA with text:

$xml .= '<![CDATA[<a target=_blank href="mymap/picture.jpg"><img src="mymap/picture.jpg"/></a>]]>';
-then it works.

RE: Link to image in CDATA

I should say: what I need is a output like this:


 <?xml version="1.0" encoding="UTF-8" ?>
- <gpx>
- <metadata>
- <extensions>  
- <wpt lat="55.68316" lon="11.82938">
- <extensions>
- <html>
- <![CDATA[ <a target=_blank href="mymap/picture.jpg"><img src="mymap/picture.jpg/></a>

RE: Link to image in CDATA

If you can replace like that, then you can replace until any thing works for you in any manner you like. That's not my problem.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close