473,549 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="check ed" ';?>/>

OR:

<?php if($config['item']) echo '<input type="checkbox" id="something"
checked="checke d" />'; 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 9001
Hi,

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

$attrs = $node->attributes('ht tp://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="check ed" ';?>/>

OR:

<?php if($config['item']) echo '<input type="checkbox" id="something"
checked="checke d" />'; 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
5076
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 the days before PHP got object-oriented features. For instance we currently have:
1
2709
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 namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For...
1
2958
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 <core:District Id="AB01"> <core:Name>NORTH EAST</core:Name> <core:Association Type="type1">VALUE 1a</core:Association>
1
1453
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 should be resolved. I'm actually only just starting to use SimpleXML with any vigor, so I may well be mistaken about what I think it should do... ...
1
2666
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 id=\"2\">Susie Q. Public</person>
5
2089
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 to make a simple CMS based on a page with a form containing 2 fields (text description and picture uploader), wich data (the text and the path to...
5
1723
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> <title>Moonlight</title> <year>1978</year>
7
2909
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: <xmlfile> <object foo="bar"> <color mode="rgb">ffddee</color> </object>
1
4380
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> <name>Author</name> </author> <source:resource url="http://somesite.com?tid=123456"/>
0
7542
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7736
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7982
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7500
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7827
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.