You are here: simplexml and attributes with a namespace in front. How do you get the attribute? « PHP Programming Language « IT news, forums, messages
simplexml and attributes with a namespace in front. How do you get the attribute?

Posted by fido on 07/07/07 04:59

Here's a bit of xml code that works.

<?php

$string =
"<?xml version=\"1.0\" standalone=\"yes\"?>
<world>
<people xmlns:ss=\"http://crap\">
<person id=\"5\">John Doe</person>
<person id=\"2\">Susie Q. Public</person>
</people>
</world>";

$xml = simplexml_load_string($string);
print "<pre>\n";
print_r($xml);
print "</pre>\n";

foreach($xml->people->person as $p)
foreach($p->attributes() as $a => $b)
{
print "$a => $b<br />\n";
}

// prints out
// id => 5
// id => 2
?>

Now what if I change the first person to this
<person ss:id=\"5\">John Doe</person>

Anyone know how to get the id?

This is a question that is pertinent to an excel .xml file as
you'll get lines like this
<Cell ss:Index="3">stuff</Cell>

btw: there is a guide on ibm that tells you how to do this with php
and dom. I'm just wondering if there's a way to do it with simplexml.

thx.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация