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.
Related
I currently have an XML file(http://redmine.something.com/projects.xml). I want to read that data to insert into my database using PHP function which I don't know how to write the function to get the data. Below is my example of that XML file structure:
<projects type="array" total_count="7" offset="0" limit="25">
<project>
<id>147</id>
<name>012-003: online shop jakob schlaepfer</name>
<identifier>012-003</identifier>
<created_on>2012-02-01T09:14:29+07:00</created_on>
<updated_on>2012-02-20T10:58:28+07:00</updated_on>
</project>
</projects>
Any link or help would be really appreciated. Thanks.
You're looking for SimpleXML. Here are some basic examples.
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.
I want to set hyperlink in the image in XML file.
Here is my code of XML file:
<logos>
<logo id="1" name="Abc" path="abc.jpg" x="23" y="4" height="10" width="60"/>
<logo id="2" name="Xya" path="xyz.jpg" x="50" y="`4" height="20" width="40"/>
</logos>
I want to set hyperlink in this image.
XML is a generic data format. It doesn't have any hyperlink capabilities. A specific XML application can (XHTML, for example, has the a element).
If the XML application you are using doesn't include anything to describe hyperlinks, then you need to change it, possibly by importing something from another namespace (such as XLink).
The software that consumes the application will almost certainly have to be updated to add support for the change you make to the language.
I would set an attribute in the node for link_out like:
<logo link_out=""...
Or create a child element to the Logo node if multiple links will ever be in use.
Really hard to understand your need for this.
what XML structure are you following? If you aren't following one, what is stopping you from doing something like:
<logos>
<logo>
<image blah="">
<link blah="">
</logo>
</logos>
Hard to help you when there are a myriad of solutions, but we don't have all the details.
In the XML file, you need to tell it to ignore tags that are intended as html
tags and not tags of the xml structure by enclosing the html using
<![CDATA[ your html ]]>
<urlLink><![CDATA[ Click Here ]]></urlLink>
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.