Amal Antony
Amal Antony

Reputation: 6837

Preventing PHP from auto parsing XML

I'm making an api call to a site using the code as shown below :

 $xmlData = file_get_contents("http://isbndb.com/api/books.xml?access_key=XXXXXX&index1=isbn&value1=0596002068");

 echo $xmlData;

However xmlData when displayed on the browser is auto parsed to HTML. For e.g. The element <title> of the returned XML which is actually a book title is converted to HTML essentially becoming the page title, and the other XML elements are displayed as plain text without the tags. I want the client side XMLHttpRequest Object to get raw XML data from the server side.


Why does this happen and how do I ensure that XML is not auto parsed?

Upvotes: 0

Views: 159

Answers (2)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

PHP just sees it as text. For instance, do echo "<b>Bold</b>"; and it will "automatically" be in bold. It is the browser that processes the HTML and renders it.

This is what htmlspecialchars is for.

Upvotes: 4

Marcin Orlowski
Marcin Orlowski

Reputation: 75635

This got nothing to do with php. you spit out elements which browser interprets as HTML (that's why it sets title). Build your html page right, use <pre> tags around your content, or. when needed, send your content with correct content-type header (like text/plain to display your xml for viewing or text/xml for other purposes) so it will not parse your data as html.

Upvotes: 1

Related Questions