By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,825 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,825 IT Pros & Developers. It's quick & easy.

DOMXML get unknown Attributes

P: n/a
Hey List,

I was wondering how I can get all Attributes of a XML-Tag without
knowing them. The XML could look like following:

<plugin>
<args level="1" depth="2"/>
</plugin>
<plugin>
<args permission="23"/>
</plugin>

Now both plugins use different Attributes in the args tags and the
program doesn't know them. Is there a way to get them? Put them into
an array? I am using PHP5
Thanks a lot and best regards,

Nikolai Onken
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Nikolai Onken wrote:
Now both plugins use different Attributes in the args tags and the
program doesn't know them. Is there a way to get them? Put them into
an array? I am using PHP5
Thanks a lot and best regards,


Since the DOM function DocumentElement::getAttributes() doesn't seem to be
implemented, you could, per example, use the simplexml extension instead:

<?php

$xml = <<<EOXML
<plugins>
<plugin>
<args level="1" depth="2"/>
</plugin>
<plugin>
<args permission="23"/>
</plugin>
</plugins>
EOXML;

$dom = new DomDocument;
$dom->loadXML($xml);

$s = simplexml_import_dom($dom);

foreach ($s->plugin as $plugin) {
foreach($plugin->args[0]->attributes() as $n => $v) {
print "$n => $v<br />";
}
}

?>
HTH;
JW

Jul 17 '05 #2

P: n/a
Nikolai Onken <in**@nikolaionken.com> wrote:
Hey List,

I was wondering how I can get all Attributes of a XML-Tag without
knowing them. The XML could look like following:

<plugin>
<args level="1" depth="2"/>
</plugin>
<plugin>
<args permission="23"/>
</plugin>

Now both plugins use different Attributes in the args tags and the
program doesn't know them. Is there a way to get them? Put them into
an array? I am using PHP5
Thanks a lot and best regards,

Nikolai Onken


Since the XML-document should follow a specific DTD, you should know
*every* possible attribute. If you are just beginning to create such a
structure, maybe you can change it to something like:

<plugin>
<arg name="level" value="1" />
<arg name="depth" value="2" />
</plugin>
<plugin>
<arg name="permission" value="23" />
</plugin>
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #3

P: n/a
On Thu, 23 Sep 2004 08:57:50 +0200, Simon Stienen
<si***********@news.slashlife.de> wrote:
<plugin>
<arg name="level" value="1" />
<arg name="depth" value="2" />
</plugin>
<plugin>
<arg name="permission" value="23" />
</plugin>


Hey Simon,

I was thinking about that and its true - otherwise the idea of XML
wouldn't really be followed... I'll use the name="" value="" instead.
Thanks for your help!
Regards,

Nikolai
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.