PHP How do I serve an XML file as a web service in PHP?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How do I serve an XML file as a web service in PHP?

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Question How do I serve an XML file as a web service in PHP?

    I would like to have a web service in PHP simply send an existing XML file - this is to get around the cross-site XMLHttpRequest limitation. I need to read it in JavaScript on the client end.

    Can this be done?

    I am a PHP n00b, so any code example some kind soul can provide would be greatly appreciated.

    :-)

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,867

    Re: How do I serve an XML file as a web service in PHP?

    All you need is to set your header for XML content and then output pure XML.

    PHP Code:
    <?php
    header 
    ("Content-Type: text/xml");

    echo 
    $xmlContent;
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    Re: How do I serve an XML file as a web service in PHP?

    That's cool, but I think you're still limited by JavaScript's inability to read a file located on another server. I was really looking to make it into a Web Service I can call.

    Thanks, though, I did learn something.

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,867

    Re: How do I serve an XML file as a web service in PHP?

    You misunderstand JavaScript's cross-domain policy. JavaScript can read files on other domains...it cannot interact with DOM elements on other domains.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center