phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


SimpleXML: Creating a SimpleXMLElement

Tag: SimpleXML, SimpleXMLElement, XML   Category: PHP Basic
post: 17 Apr 2008 read: 997


PHP SimpleXML Step By Step Tutorial - Part 1: The SimpleXML extension is another xml parser available in PHP5. We ever talk about xml parser tips at here. SimpleXML make our job more easy. I takes a different approach to handling the tree. This extension has a single class type, three functions, and six class methods.

Ok, first part of this tutorial series about SimpleXML, we create a XML document use SimpleXMLElement. We use new keyword to be directly instantiated using an XML document within a string as its data source. See like this:


$xml = "<library><book>PHP EveryDay</book></library>";
$sxe = new SimpleXMLElement($xml);

SimpleXML have asXML() method. With this method, we can output a document or substree to a string or a file. If you want to print to browser, you can use like this:


$xml = "<library><book>PHP EveryDay</book></library>";
$sxe = new SimpleXMLElement($xml);
print $sxe->asXML();

You can see above. When no parameter is passed to this method, the results are returned as a string. If we want to save to a file, we can use like this:


$xml = "<library><book>PHP EveryDay</book></library>";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML("test.xml");


Series this article:
SimpleXML: Creating a SimpleXMLElement
SimpleXML: Creating XML Document From Database
SimpleXML: Accessing Element
SimpleXML: Using Iterable Object
SimpleXML: Accessing Unknown Element
SimpleXML: Creating File Contain Part of Another XML Document
SimpleXML: Mixing With DOM Interoperability

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting