473,494 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simplexml + Namespace +attributes

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>
<core:Association Type="type2">VALUE 1b</core:Association>
<core:Association Type="type3">VALUE 1c</core:Association>
</core:District>
<core:District Id="AB02">
<core:Name>NORTH WEST</core:Name>
<core:Association Type="type1">VALUE 2a</core:Association>
<core:Association Type="type2">VALUE 2b</core:Association>
<core:Association Type="type3">VALUE 2c</core:Association>
</core:District>

I'm trying to parse it using simplexml

I have:

$districts = $xmlfile->children($core);

foreach ($districts as $key => $value)
{
echo "Name = " . $value->Name . "\n";
echo "Region1 = " . $value->Association[0] . "\n";
echo "Region2 = " . $value->Association[1] . "\n";
echo "Region3 = " . $value->Association[2] . "\n";

}

This works fine, but I am unable to access the Id attribute in the
opening District element, i.e. AB01 or AB02.

Would anyone be able to suggest how I might get that value with
simplexml?

Many thanks,

Russell
Dec 14 '05 #1
1 2949
District ID is an attribute of an element, not a child. Therefore to
read it you must use syntax simular to

$xml->District['ID']

Dec 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2698
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
1451
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
2664
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
2088
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...
1
8981
by: WebCM | last post by:
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"...
5
1719
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
2906
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:...
3
12933
by: SM | last post by:
I think that simpleXML is the best thing i've seen in PHP5. It's so simple (d'ho!) and easy to use when it comes to reading a simple XML file. The only thing i'm not sure how to achieve is...
1
4375
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
7119
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,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
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,...
0
7195
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...
0
7367
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...
0
5453
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,...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
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 ...

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.