phpeveryday.com

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


SimpleXML: Creating File Contain Part of Another XML Document

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


PHP SimpleXML Step By Step Tutorial - Part 6: If we want to create a XML Document that contain part of another XML Document, we can combine asXML and SimpleXMLElement. For example see like this:

<?php
$lib  = simplexml_load_file("test.xml");
$lib->book->asXML("test2.txt");

?>

Result become like this:


<book>
  <id>1</id>
  <title>PHP AJAX</title>
  <author>Andreas</author>
  <description>This is good book for learning AJAX</description>
  <on_sale>1</on_sale>
</book>

From above, we take one subtree and enter to new file named "test2.xml". From code above, you can practice with other such as:


<?php
$lib  = simplexml_load_file("test.xml");

$title = $lib->book->title;
$title->asXML("test2.txt");

?>


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
mod_rewrite - Part 1: create your "fantasy" URL

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


615
posting