473,387 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DOMXML get unknown Attributes

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
3 1796
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ghislain Benrais | last post by:
Hello, My "problem" : install php's XSLT API. 1)I installed Sablotron (with the rpm) : ok 2) I read every where that the next step was to compile php with option --with-xslt-sablot. Since I have...
0
by: Terence | last post by:
The XML (expat) extension to PHP contains specific functions for accessing detailed error information when an error occurs parsing an XML packet. All be it convoluted, even the XSLT (Sablotron)...
3
by: srommens | last post by:
Hello, When I try to do : URI = <xsl:value-of select="//@URI"/><br/> <xsl:if test = "//@URI != '5-42922'">not equal</xsl:if><br/> <xsl:if test = "//@URI = '5-42922'">equal</xsl:if><br/> ...
0
by: bissatch | last post by:
Hi, I have installed Apache2. I have installed PHP4.3.0. All is working fine. I have now went and tried to install DOMXML into PHP by simply uncommenting the extension = php_domxml.dll (or...
3
by: bissatch | last post by:
Hi, I have recently installed PHP4 with Apache2. Currently I am trying to install the DOMXML extension. According to what I have read, if I uncomment the extension=php_domxml.dll line in php.ini...
5
by: fjanon | last post by:
Hi, I went through the HTML spec without finding the description of what the browsers behavior should/must be regarding tags or attributes they don't understand. I did a quick experiment like...
1
by: dhiraaj1983 | last post by:
I have been trynig to implement the Google Adwords API in my account. For this i downloaded their API library with PHP scripts to run the projexct. It required me to uncomment php_curl.dll and...
2
mageswar005
by: mageswar005 | last post by:
hi, I installed php5 in linux server, inside the usr/lib/php5 the domxml.so file is missing,without domsml.so i can'nt able to import scorm packages. How can i install domxml.so to my linux...
2
mageswar005
by: mageswar005 | last post by:
Hi guys, Any body have any idea about php5 domxml with obuntu linux server. I have installed php5,Apache2,Mysql on linux ubuntu server,but Domxml is not working properly.I dont know why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.