I have a xml file on my server. I have the following two questions.
Thank You
You would use these two commands:
<?php
header('Content-type: text/xml');
readfile('/path/to/file.xml');
You didn't say anything about receiving XML on the server, so I'm not sure what you mean by parsing.
Regarding parsing XML in JavaScript... I defer to someone with more experience.
set the content type in the HTTP response using the header() function as:
header('Content-Type: text/xml');
then you can write the xml file content.
You must call hearder() before any output is sent.
On client side you can parse the XML in JavaScript using DOM.
gahooa's code to send the XML file to the client should work just fine. In JavaScript, you can use the XML parser to read and manipulate it. However, this is not the approach I would recommend.
Instead, let the server convert your XML into JSON after using PHP's file_get_contents()
to read the XML to a string. JavaScript can natively evaluate JSON.
You'll find that navigating the DOM of an XML is clumsy by comparison to working with native JSON.