[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML with PHP


php header xml
3/5/2002 11:52:21 AM, "Marksman" <chris_ziel@y...> wrote:

,
>    i want to build a page with server-side parsed XML.
>    Bit i dont know how to use XML with PHP.


Here are a few resources I found interesting/useful.  They
are totally DOM-centric ... although
the PHP DOM interface is highly non-standard.

http://www.php.net/manual/en/ref.domxml.php

The "user contributed notes" are the most useful part of the manual!

http://www.devarticles.com/art/1/44
http://www.devshed.com/Server_Side/XML/XMLwithPHP/XMLwithPHP1/page1.html
http://www.devshed.com/Server_Side/XML/XMLwithPHP/XMLwithPHP2/page1.html

Here's a trivial php program that takes a POST of an HTML form
(the names of the fields are automatically represented as PHP
variables), opens an RSS-like file identified by the $file value,
and puts the form information in a new "item" element at the bottom
of the first "channel" element, then rewrites the file and echoes
its contents to the browser. 

<?php

  header ("content-type: text/xml");

    	$file = "http://localhost/log/" . $arch . ".xml";
    	$doc = xmldocfile($file);

	$ctx=xpath_new_context($doc);
	$c=xpath_eval($ctx,"//channel");
      $r = $c->nodeset[0];
	$i = $r->new_child("item");
	$i->new_child("title", $head);
	$i->new_child("link", $link);
	$i->new_child("description", $comment);

    	$out = domxml_dumpmem($doc);
    	$file = $arch . ".xml";
    	$f = fopen($file, 'w');
    	fputs($f, $out);
    	fclose($f);

	echo $out;
?>


I am a complete PHP novice, so any
suggestions to do things in a more sensible way would be appreciated.




  • References:

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.