phpeveryday.com

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


SimpleXML: Mixing With DOM Interoperability

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


PHP SimpleXML Step By Step Tutorial - Part 7: When we work with unknown elements, we can use DOM interoperability. First, we import nodes into the DOM extension. Next, access them using DOM properties and methods. See this sample:

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

$children = $lib->book->children();

foreach($children as $child){
  $element = dom_import_simplexml($child);
  $name = $element->nodeName;
  print $name.": ".$child;
  
}

?>

You may get like this:


id: 1title: PHP AJAXauthor: Andreasdescription: This is good book for learning AJAXon_sale: 1

After importing nodes to the DOM extension, we can perform anything that supported by DOM like add new element, edit, or remove element.



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