I want to show XML file on my page, I have set the header header('Content-Type: application/xml')also tried for header(application/rss+xml),
but my URL can not show the page in XML format but in View Page Source it created the XML file
URL- http://submitsitelink.com/rss.php?p=d
Can you please help me ?
Thanks
Google Chrome can neither read RSS nor beautify XML natively. You have to find and install an extension:
RSS Subscription Extension
XML Tree
It sounds like you want to style the output of your XML - one method of doing this is via XSL technologies. You can also add CSS stylesheets to XML documents by adding something akin to the following near the top of your XML document.
<?xml-stylesheet href="common.css"?>
As far as I know you cannot do this with HTTP headers, only by modifying the XML document itself.
Related
I have this code (part of bigger script):
flashvars.xmlSource = "datasource.xml";
datasource.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<Object>
<Contents>
<Source="address" Title="title"></Source>
<Description><h1>New hot Features</h1><p>The all new Piecemaker comes with lots of new features, making it even more slick.</p><p>Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.</p><p>We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.</p></Description>
(...)
</Contents>
</Object>
I want to generate datasource.xml dynamically using foreach loop.
I've just changed the file extension to .php but this is not that easy ;)
Any ideas?
Funny or not, but try this one:
leave your file extension to be "xml"
where you wrote (...) write <? PHP CODE HERE ?>
So handle it as if it would be some html file. What I mean is:
<?xml version="1.0" encoding="utf-8"?>
<Object>
<Contents>
<Source="address" Title="title"></Source>
<Description><h1>New hot Features</h1><p>The all new Piecemaker comes with lots of new features, making it even more slick.</p><p>Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.</p><p>We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.</p></Description>
<? create php loop here ?>
</Contents>
</Object>
Also note
this line
<Source="address" Title="title"></Source>
might be wrong (you assigned some value to the tagname), try
<Source name="address" Title="title"></Source>
or something like that.
As I see generating xml file with php could be done in this way - for example you'll create file datasource.xml which will be not a static xml file but xml with php code included with contents like
<?php //php code to generate any xml code as Text
// it can be whatever you need to generate
// for example
$content="<h1>New hot Features</h1><p>The all new Piecemaker comes with lots of new features, making it even more slick.</p><p>Just to mention a few - you can now specify unlimited transition styles, include your own SWF and Video files, add hyperlinks to images and info texts with all special characters.</p><p>We also impoved the navigation and the animation with animated shadows and pixel-perfect transitions.</p>";
$output="<Description>".$content."</Description>";
header('Content-type: application/xml');// this is most important php command which says that all output text is XML it must be called before any line of xml will be printed.
// So you need at first generate XML as text then call this command and echo contents of your xml file.
?>
<?xml version="1.0" encoding="utf-8"?>
<Object>
<Contents>
<Source name="address" Title="title"></Source>
<? echo $output; ?>
</Contents>
</Object>
In order to allow php to execute php code inside XML file we need to add some directives to apache host configuration file. In my case I added
<IfModule mod_php5.c>
<FilesMatch "\.xml$">
SetHandler application/x-httpd-php
</FilesMatch>
inside my virtual host configuration file, or you can place this command inside .htaccess file in your directory if Override of this param is allowed in your host configuration.
And about xml- to make sure it's ok you can use http://validator.w3.org/ or http://www.w3schools.com/xml/xml_validator.asp to validate xml generated by your script.
Does this XML need to be a stored file somewhere on the server, or can you just pass it a string formatted like the XML you mentioned. You could write a function that generates the XML you're looking for and returns it, based on input and then call that like
function generateXML($input){
$xml = '<?xml version="1.0" encoding="utf-8"?><Object><Contents>
<Source="address" Title="title"></Source><Whateverelse>' . $input;
$xml .= '</Whateverelse></Contents></Object>';
return $xml;}
flashvars.xmlSource = generateXML("This is whatever else");
If you need to actually generate and store a well formed XML document, or if your XML is fairly complex and you need to generate an object rather than just using a string, you can utilize one of the PHP libraries to do this like http://php.net/manual/en/book.simplexml.php
I have xml storage with in this format
<Contacts>
<Contact>
<![CDATA["Some HTML"]]>
</Contact>
<Contact>
<![CDATA["Some HTML"]]>
</Contact>
</Contacts>
I am using XMLHttpRequest to read the data and put it inside a "div" on the page. Now I make some changes on it via JavaScript and I would like to know how can I update the changes made back to the XML file from where I took the data.
I've been googling a lot but I have problems understanding those forums because they are not describing examples similar like mine.
Try using a ajax call which you give the xml data. You can then save the data using simplexml http://nl.php.net/manual/en/book.simplexml.php or using http://nl.php.net/manual/en/book.domxml.php
Leave the "retrieving" your XML on JavaScript, and "saving changes" on PHP. Using jQuery you just $.get() your XML file, and when you save it (let it be .click, .live('click') etc.)
you $.post() strings you wrote in some input to something like save_xml.php. There are some tools for working with XML files in PHP. If you get on well with Smarty, I advise you to keep sort of my_xml_template.tpl , which after smarty->fetch you save in a file with file_put_contents(). Cheers.
I'm trying to create an xml-based template system. The idea is to return my views as xml files (xhtml) and then append them to specific nodes in a template xml file. The template xml is then transformed with xslt.
My question is: how do I insert these xml files into the template xml file?
See DOMDocument::importNode and DOMNode::appendChild.
I'm trying to get an html page to display an XML file formatted with an XSL stylesheet. Whatever examples I see are either displaying it in a new page, with the XSL stylesheet taking care of the tags, but no examples where I can clearly see it being displayed as part of an existing webpage...
I'm using a PHP script to generate the HTML. And the XML data is being generated by another PHP function (not under my control). The XSL file is uploaded on the server and stored at: /xsl/1234567890.xsl
Here's what the php outputs:
<html>
...
<body>
...
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/xsl/1234567890.xsl"?>
...
<xml tags>
...
What am I doing wrong?
Two ways to transform the XML:
1 browser
Most browsers implement XSLT processors. You could use:
<iframe src="xml-source.xml"/>
The users will have to make three requests (page, xml, xsl) and unless you want inline scrollbars you'll need some Javascript to resize the iframe.
2 server
You can run a XSLT processor on the server side and return the transformed XML. There are many ways to do this, here is one in PHP. With caching you shouldn't run into any performance problems and also support browsers without internal XSLT processors (e.g. mobile devices).
Ive been trying to display formatted content blocks from a xml file with no luck. Ive been using simplexml_load_file and other varients which Im now seeing cannot deal with the xhtml tags within the called tag ... eg.
//php contents
<?php $xml=simplexml_load_file("file.xml");
echo ($xml->entry); ?>
//xml contents
<entry>
<p>This does not work</p>
</entry>
whereas
<entry>This works</entry>
can someone please tell me which php function can do this from an xml file and or
what is the best way to display the contents with xhtml formatting?
Im trying to dynamically load content to a webpage without having to build too many pages. I like the idea of having all my content in one xml file for easy edits.
Theres not enough content to justify a database yet.
Thanks in advance
You can try dumping the contents of a certain simplexml node (in this case: $xml->entry) using the asXml function.
echo $xml->entry->asXml();
Check the php documentation on simplexml here (link to the asXml() call):
Simplexml documentation
im getting closer... I found asXML() which outputs the html tags... but not sure yet how to point to specific blocks.... eg $xml->asXML(block) displays 1
got it
$xml->block->asXML()
works
would still like to know if there is a better method tho.