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

problem when outputting an xml file using php

Hi there,

I am trying to output a file, coutries.xml, which is in the following
format:

<xml...
<countries>
<country id="1">Afghanistan</country>
<country id="2">Albania</country>
Jul 17 '05 #1
3 1361
mr_burns wrote:
It is managing to output the 'id' attribute but the node value isnt
appearing. Can anybody tell me how to sort it? Cheers


Switched over to PHP 5 already? Then try the following:

<?php

$xml_document = new DomDocument;
$xml_document->load('xml/countries.xml');

if ($xml_document) {
$items = $xml_document->getElementsByTagName('country');
for ($i = 0; $i < $items->length; $i++) {
$item = $items->item($i);
print $item->getAttribute('id') . " = " . $item->nodeValue . "<br>";
}
}

?>
JW

Jul 17 '05 #2
Hi,

I tried your code but got the following error:

Warning: domdocument() expects at least 1 parameter, 0 given in
/home/martyn69/public_html/oarsome/test_countries.php on line 35

Fatal error: Call to undefined function: load() in
/home/martyn69/public_html/oarsome/test_countries.php on line 36

It seems that the code I am using is opening the XML file, getting
into the FOR loop and is managing to spit out the 'id' attribute. The
only problem is the $item->node_value() isnt producing the node value.

Any ideas? Why isnt node_value() producing the node value? Am I
missing something? Cheers

Burnsy
Jul 17 '05 #3
Ive just posted a reply saying that I was still having trouble (this
one might beat it to it though).

I have managed to sort node_value(), Ive used get_content() instead
and its working now. Cheers
Jul 17 '05 #4

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

Similar topics

2
by: Dariusz | last post by:
I have a problem where when I run the PHP code offline, there are no errors produced and the code runs as expected. However when I uploaded the same script and run it, it says the headers have...
2
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
7
by: B. Williams | last post by:
I wrote a program that would simply output data to the screen, but now I am trying to have the data saved to a file. I don't have a problem creating the file or even outputting data to it when there...
2
by: imarinoff | last post by:
Hi I have a problem with the following code. #include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv)
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
11
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to a string then normalizing the strings. Then I'm...
12
by: billelev | last post by:
This is probably a very easy question to answer: I have been outputting some text to a message box, similar to the following: strOutput = "---" & Chr(10) & Chr(10) strOutput = strOutput &...
1
by: Christoph Boget | last post by:
I'm experiencing a very odd problem and it's happening only in IE6. IE7, Safari, Opera and Firefox are all working properly. What's happening is that I'm using XHR request responses to update the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.