473,589 Members | 2,585 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 9010
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
5105
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
2717
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 example, are the following equivalent: <html:br class="foo"...
1
2966
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
1455
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... Basically, if you take this simple chunk of XML:
1
2667
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
2092
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 the picture file in the server) is stored in a xml file.
5
1727
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
2913
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
4384
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
7931
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8233
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8360
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7990
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6637
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5399
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3889
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1461
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1198
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.