SimpleXML - how to get attributes with namespace? + XML vs. preg_*

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
There are lots of problems with XHTML parsing in PHP by XML functions.
I've just solved most of them. However, how to get value of attribute
with namespace?

<input type="checkbox" id="something" f3:var="config.item" />

foreach(xpath('//input[@id="ms"]') as $item) echo $item['f3:var'];

It doesn't work. Even $f3->item['var'].

I wonder whether parsing XML using preg_* and str_* wouldn't better.
Though i'm only creating a template system. XML parsing is only used
for FORMS with IF conditions generating. Example output:

<input type="checkbox" id="something" <?php if($config['item']) echo
'checked="checked" ';?>/>


<?php if($config['item']) echo '<input type="checkbox" id="something"
checked="checked" />'; else echo '<input type="checkbox"
id="something" />'; ?>

There is only 1 (later maybe more) new attribute: f3:var - which can
be situated in <form> (for all checkbox, radio and select) or in
input / select elements.

Give me some advices. What is better for this purpose - XML in PHP or
preg_* / str_*?

Re: SimpleXML - how to get attributes with namespace? + XML vs. preg_*


Pass the namespace URI to the attributes method to access prefixed

    $attrs = $node->attributes('http://example.test/myNamespace ');
    echo $attrs['myAttribute'];

More info at:


John Peters

Quoted text here. Click to load it

Site Timeline