0

I am trying to simply display contents of a XML file in an HTML list. For some reason the result remains empty and I don't know why. I did check out many of the questions and answers but still did not succeed.

Here is the code at JSbin: http://jsbin.com/arufep/edit

The goal is to have a list of clickable url's like this:

<li><a href="/dir/xyz.htm">description</a></li>

Thanks for looking into it.

2 Answers 2

1

You're attempting to make a cross-domain ajax call to http://www.halo-photographs.com/test-code/panorama-list1.xml which is not allowed by the browser's Same Origin Policy.

You can look into JQuery's crossDomain:true ajax parameter to accomplish this but I believe it will not work with an XML response.

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

3 Comments

That XML file is located on that same domain which is my server.
Try giving it a relative url path instead of an absolute path
Your are correct to use a relative path. But still there is no result, the alert-box in jsbin says [object Object] and the same page downloaded from jsbin reveals the content of <h2> only. So my assumption is that something in JavaScript code is still not as it should be to display the contents of that XML as an HTML list <li>.
0

Below is the PHP5-page to used to insert data originating from an XML-file without client-side scripting.

Make sure your XSLT outputs what you intend to have displayed.

Comment: I must admit my initial question referred to jQuery, but I ended up with this rather simple and effective solution instead.

<?php
  $path_xml = "/...path-to.../list.xml";
  $path_style = "/...path-to.../list.xsl";  
  $xml_obj = new DomDocument;
  $xsl_obj = new DomDocument;

  if (!$xml_obj->load($path_xml)) {
      echo "Error! Unable to open " . $path_xml . "!\n";
      exit;
  }
  if (!$xsl_obj->load($path_style)) {
      echo "Error! Unable to open " . $path_style . "!\n";
      exit;
  }
  $xslt_parse = new xsltprocessor;
  $xslt_parse->importStyleSheet($xsl_obj);
?>
<!DOCTYPE...>
<head>
</head>
<body>

<p><!-- display XSLT-styled content of XML-data here: -->
    <?php echo $xslt_parse->transformToXML($xml_obj);?>
</p>
</body> 
</html>

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.