Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

63 users online



php simplexml

php simplexml

Currently viewing this thread: 1 (0 members and 1 guests)


sapphire

sapphire

Neverside Newbie
Status: Offline!

php simplexml

im having trouble using simplexml to read an xml file that uses a namespace prefix. heres my xml

Code:

<?xml version="1.0" encoding="UTF-8"?>
<mu:mash xmlns:mu="#"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="#" title="m3net" author=".clicky">
<mu:img id="test" src="http://a345.ac-images.myspacecdn.com/images01/64/m_d347d48c72b56a7e06decb94da2f84c8.jpg"/>
</mu:mash>

and heres my php

PHP:

<?php
class XMLParser {

    var 
$xml;
    var 
$currentTag;
    
    function 
XMLParser($str) {
        
$this->xml simplexml_load_file($str);
        echo(
"Mashup: ".$this->xml['title']." by ".$this->xml['author']."<br/><br/>");
    }
    
    function 
readChildNodes() {
        echo(
"hello");
        foreach (
$this->xml->children() as $item) {
            echo(
$item['src']);
        }
    }
}

$xml_p = new XMLParser(url);
$xml_p->readChildNodes();
?>

it works fine upto the readChildNodes() function. this only works when i remove the mu: namespace prefix from the <img> tag. any ideas?

Last edited by sapphire, June 9th, 2007 10:43 PM (Edited 1 times)

zaron

zaron

Neverside Newbie
Status: Offline!

You need to pass the URI of the namespace to the children-Method in order to get children with the mu-NS:

PHP:

<?php
function readChildNodes() {
    echo(
"hello");
    foreach (
$this->xml->children('#') as $item) {
        echo(
$item['src']);
    }
}
?>

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0172 seconds.