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

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

P: n/a
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" />

<?php
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" ';?>/>

OR:

<?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_*?
Jun 2 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Pass the namespace URI to the attributes method to access prefixed
attributes:

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

More info at:

http://www.php.net/manual/en/functio...attributes.php

Regards,

John Peters

On Apr 25, 2:25 pm, WebCM <webcm...@gmail.comwrote:
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" />

<?php
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" ';?>/>

OR:

<?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_*?
Jun 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.