473,320 Members | 1,846 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,320 software developers and data experts.

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

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

Similar topics

88
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
1
by: root | last post by:
Hi folks - hope someone can help me. Firstly, my apologies for crossposting this to alt.php (and not properly crossposting either). I have an XML file with some elements like those below ...
1
by: Andy | last post by:
Hi, I'm running in to a little issue with SimpleXML, and wondered if anyone knew if it was normal implementation for SimpleXML, or I'm not using a correct flag, or even it's a an issue that...
1
by: fido | last post by:
Here's a bit of xml code that works. <?php $string = "<?xml version=\"1.0\" standalone=\"yes\"?> <world> <people xmlns:ss=\"http://crap\"> <person id=\"5\">John Doe</person> <person...
5
by: Pablo | last post by:
Hello, Does anybody know any tutorial about using PHP5 SimpleXML with forms? I have found some SimpleXML examples, but only modifying node attributes from the php code directly. I would like...
5
by: SM | last post by:
Hello I have simple question using simpleXML and PHP. i have an xml file that looks like this: <?xml version="1.0" encoding="UTF-8"?> <discography version="0.01"> <CD>...
7
by: dimo414 | last post by:
So I'm trying to use SimpleXML to get some attribute information about some nodes in my XML document, but it seems like SimpleXML ignores attributes for elements with no children, For instance:...
1
by: duane.lortie | last post by:
I'm writing a routine that fetches XML and attempts to parse some values from it. A condensed entry node of the XML looks like this .. <entry> <title>Some title</title> <author>...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.