$file, "intLatitude"=>$i"> Tek-Tips: XML - Link to image in CDATA
Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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.

pknudsen (Programmer) (OP)
5 Nov 10 16:23
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(
                  "filename"=>$file,
                  "intLatitude"=>$intLatitude,
                  "intLongitude"=>$intLongitude);
                  "directory"=>$$dh;
------------------
-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>';
fwrite($file,$xml);
fclose($file);

-and the function parseToXML

function parseToXML($htmlStr)  
{  
$xmlStr=str_replace('<','&lt;',$htmlStr);  
$xmlStr=str_replace('>','&gt;',$xmlStr);  
$xmlStr=str_replace('"','&quot;',$xmlStr);  
$xmlStr=str_replace("'",'&#39;',$xmlStr);  
$xmlStr=str_replace("&",'&amp;',$xmlStr);  
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.

 
tsuji (TechnicalUser)
6 Nov 10 11:50
[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
fclose($file);


//now your desired output html file
$htmlfile="xyz.htm";

$xdoc=DOMDocument::loadXML($xml);
$xpdoc=new DOMXpath($xdoc);
$anchors=$xpdoc->query('//html');

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

$f=fopen($htmlfile,"w");
fwrite($f,"\n\n");
fwrite($f,$s);
fclose($f);

[1.3] Now you have a html file which has the rudimentary layout that gives you the desired hyperlinkage.
pknudsen (Programmer) (OP)
7 Nov 10 10:32
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.
pknudsen (Programmer) (OP)
7 Nov 10 10:44
I should say: what I need is a output like this:

example:

 <?xml version="1.0" encoding="UTF-8" ?>
- <gpx>
- <metadata>
- <extensions>  
  </extensions>
  </metadata>
- <wpt lat="55.68316" lon="11.82938">
- <extensions>
- <html>
- <![CDATA[ <a target=_blank href="mymap/picture.jpg"><img src="mymap/picture.jpg/></a>
  ]]>
  </html>
  </extensions>
  </wpt>
  </gpx>
 
tsuji (TechnicalUser)
7 Nov 10 10:46
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.

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!

Back To Forum

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