2

Im trying to link a JS library into a php dynaimcally generated xml document. except it keeps returning an error in the header? and I am having a problem with the link due to the "", which is normally used for a string in php. Any thoughts?

$id = '1232';
$name = 'Christopher';

// Send the headers
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

echo "<xml>";

echo "<id>";
echo "<name>";  
echo "</name>"; 
echo "</id>";

echo "</xml>";

I'm trying to add in a link to a js however I am unsure how to generate the code with php??

The link would look like <script src="processing.js"></script>

Is there a way to do this?

2
  • Why did you change the <> to () ??? Commented Apr 7, 2011 at 12:29
  • because in the section where it shows your question it was editing out the <element> examples. I'm kinda new... Commented Apr 7, 2011 at 12:32

2 Answers 2

1

I'm not exactly sure what your trying to do with jaavascript because I don't think you can have javascript in an xml file but if you wanted to output the js with the xml here is what your could should look like

 $id = '1232';
 $name = 'Christopher';


header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');

echo '<?xml version="1.0" encoding="utf-8"?>';
echo "\n<xml>\n";

echo "<id>$id</id>\n";
echo "<name>$name</name>\n";    ;
echo "</xml>";

echo '<script src="processing.js"></script>';

since you are outputing xml you don't want break elements in your xml instead you want new line characters to make it readable by source.

I think what your really want for the js is to just give the link location in the xml but i'm not 100% on that I'm a little fuzzy on what your trying to do

ohh and you don't need breaks in the header

** To answer your questions **

again I'm still not sure if your trying to execute javascript in xml or if you are simply trying to provided full link or relative line in the xml

so if you wanted to have a relative link adding

<jslink>processing.js</jslink>

for a full link

 <jslink>http://example.com/processing.js</jslink>

and if you want to execute the js

I think you want to put this in the xml

 <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
            src="processing.js"
            type="application/javascript"/>

however I believe that will only work in firefox

pleas see this blog for more detailson that

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your time. Im trying to generate elements in xml from php. And be able to add javascript to the elemenets. So that I create a usertype interface... Php is generating the info in xml which works but am trying to link this generated document to <link>process.js</link>??
0

might want to have a read of http://www.devarticles.com/c/a/JavaScript/JavaScript-and-XML/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.