views:

145

answers:

1

I have to create a module in a specific project, which already uses PrototypeJS.

What I have: - An XML File with information

What I want: - A simple div, which displays the (with XPath filterd) Content of the XML-File.

I am complete new to PrototypeJS and dont know where to begin, so I appreciate your help.

Blessing chris

+4  A: 

If by "local" you mean "client-side", you will have to :

  • include a file input for the user to upload the xml file to your server
  • fetch the xml file by ajax (easiest way) to have it as an xml document in your javascript
  • parse the xml file with the dedicated API
  • build an HTML representation of the content using text, images, etc. and include it in your div.

edit: to clarify the fetch part, here is how you can do it using Prototype:

new Ajax.Request('myfile.xml', {
  onSuccess: function(transport) {
    myParseXml(transport.responseXML);
  },
  onFailure: function(transport) {
    alert('Failure! Status code '+transport.status+' ('+transport.statusText+')');
  }
);

function myParseXml(xmlDoc) {
  var root = xmlDoc.documentElement;
  ...
}
Alsciende
But this is the point: How do I fetch the xml file?Local means the file is located in the same directory as my Script.
ChrisBenyamin
Ok, then it's not _local_, it's _distant_, ie on server-side as opposed to client-side. I'll edit my answer to help you understand how you can fetch the file.
Alsciende
Thats good.. And what I need. Thanks!
ChrisBenyamin