note 47255 added to function.simplexml-element-attributes
| From: | christian at koch dot net | Date: | Mon, 08 Nov 2004 20:35:16 +0000 |
| Subject: | note 47255 added to function.simplexml-element-attributes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80298@lists.php.net to get a copy of this message | ||
PHP5:: I think this is a fine solution to get the attributes easier...
<?php
class EFXMLElement extends SimpleXMLElement {
function attributes() {
return new EFXMLAttributes(parent::attributes());
}
}
class EFXMLAttributes {
private $attributes;
function __construct($attributes) {
$this->attributes = $attributes;
}
function __get($name) {
if (isset($this->attributes[$name])) {
return $this->attributes[$name];
} else {
return false;
}
}
}
if (file_exists('pref.xml')) {
$tst = new EFXMLElement(file_get_contents('pref.xml'));
var_dump($tst->plugins->plugin[0]->attributes()->name);
} else {
exit('Failed to open test.xml.');
}
?>
XML::example
<?xml version="1.0" encoding="ISO8859-1" ?>
<preferences>
<system>
EF3
</system>
<websites>
<website name="demo">
<scriptpath>/</scriptpath>
</website>
<website name="other">
x
</website>
</websites>
<plugins>
<plugin type="single" name="content" ontemplate="yes">
<tag><![CDATA[<%content%>]]></tag>
<class>EFContentPlugin</class>
<source>/ef3/plugins/EFContentPlugin.class</source>
</plugin>
<plugin type="single" name="attribute" ontemplate="no">
<tag><![CDATA[<%attribute @%>]]></tag>
<class>EFAttributePlugin</class>
<source>/ef3/plugins/EFAttributePlugin.class</source>
</plugin>
<plugin type="single" name="component" ontemplate="no">
<tag><![CDATA[<%component @%>]]></tag>
<class>EFComponentPlugin</class>
<source>/ef3/plugins/EFComponentPlugin.class</source>
</plugin>
<plugin type="double" name="klammer" ontemplate="no">
<tag><![CDATA[<KLAMMER@>]]></tag>
<closer><![CDATA[<KLAMMER@>]]></closer>
<class>KlammerPlugin</class>
<source>/ef3/plugins/KlammerPlugin.class</source>
</plugin>
</plugins>
</preferences>
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-attributes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47255
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47255&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47255&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47255&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47255&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47255&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47255&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47255&report=yes
Search -- http://master.php.net/manage/user-notes.php