npm 57
New Member
Here's the sample xml: - <?xml version="1.0" encoding="UTF-8"?>
-
<menu>
-
<entry>
-
<action>
-
Test
-
</action>
-
<title>
-
Test Menu Item 1
-
</title>
-
</entry>
-
<entry>
-
<action>
-
Test 2
-
</action>
-
<title>
-
Test Menu Item 2
-
</title>
-
</entry>
-
</menu>
And here's the php code: - <?php
-
$dom = new DOMDocument();
-
$dom->load("menu.xml");
-
$menu = new domxpath($dom);
-
foreach($menu->query("//menu/entry") as $entry) {
-
echo "Action is: " . $menu->query('.//action',$entry)->item(0)->nodeValue;
-
echo "Title is: " . $menu->query('.//title',$entry)->item(0)->nodeValue;
-
}
-
?>
So why, when I view the page, do I get this error: Parse error: parse error, expecting `','' or `';'' in /home/httpd/vhosts/csnradio.com/www/test/2.php on line 6
I'm really clueless as to why this would happen because there are tutorials all over the place that are quite similar to this.
Thanks in advance!
18 1577 code green 1,726
Recognized Expert Top Contributor
You have a basic syntax error, that is all.
The error mesage points to where the error is (possibly the line above), which is line 6.
It is not obvious in the code supplied
Markus 6,050
Recognized Expert Expert
Code Green, I don't see it?
npm 57
New Member
I can't use SimpleXML because the server is running PHP 4.1.2. If I'm not mistaken, one needs version 5 to use SimpleXML, right?
I can see that the error is expecting a comma or a semicolon, but I don't know enough about php to know where they would go. Especially because the code is basically copied straight from a tutorial from someone who most likely had it working on their end.
Markus 6,050
Recognized Expert Expert
I'm struggling to spot the syntax error, also.
And you're using PHP4? Seriously? It's 2011!
npm 57
New Member
I know...
I don't see where the error is AND it's been almost 7 years since 5.0.0 was released!
code green 1,726
Recognized Expert Top Contributor
Can I stop what seems to be a misunderstanding.
I don't see a syntax error. I don't even believe the error is in the code provided.
I thought npm was panicking because there was an xml parsing error.
I was trying to correct this assumption because the message is a php syntax error.
Now, what we need to see is the block of code, and 'line 6' pointing out.
Sorry for the confusion
npm 57
New Member
Would the error be a setting or something with the actual server or in that version of PHP (4.1.2)?
I just don't see where the "," or the ";" should go.
This might be something, but I don't know what:
I switched both of the "echo" commands in lines 6-7 to "print" and now I get this error: Parse error: parse error in /home/httpd/vhosts/csnradio.com/www/test/2.php on line 6
The error is in the same line, but it's different, right?
npm 57
New Member
Sorry, just for clarification, here's a visual of what I changed it to: - <?php
-
$dom = new DOMDocument();
-
$dom->load("xml.xml");
-
$menu = new DOMXPath($dom);
-
foreach($menu->query("//menu/entry") as $entry) {
-
print "Action is: " . $menu->query('.//action',$entry)->item(0)->nodeValue;
-
print "Title is: " . $menu->query('.//title',$entry)->item(0)->nodeValue;
-
}
-
?>
Try creating a new variable:
$entries = $menu->query("//menu/entry");
Now do print_r($entries). Does it print anything? If so, keep the new variable and replace $menu->query("//menu/entry") in your foreach with $entries.
Edit: comment out the entire for loop before doing print_r or the error might still happen.
npm 57
New Member
Just to make sure...change it to, and run the following? - <?php
-
$dom = new DOMDocument();
-
$dom->load("xml.xml");
-
$menu = new DOMXPath($dom);
-
$entries = $menu->query("//menu/entry");
-
print_r($entries);
-
?>
Markus 6,050
Recognized Expert Expert
I'm going to compile the same PHP version and see if I get the same error.
npm 57
New Member
I ran the above code and got this: Fatal error: Call to undefined function: load() in /home/httpd/vhosts/csnradio.com/www/test/2.php on line 3
Now what?
You didn't have to completely remove the foreach loop, but yes, run that and see what output you get.
Try creating a new variable:
$entries = $menu->query("//menu/entry");
Now do print_r($entries). Does it print anything? If so, keep the new variable and replace $menu->query("//menu/entry") in your foreach with $entries.
Markus 6,050
Recognized Expert Expert
HaLo, I think we might be forgiven for this, considering PHP4 is almost a million years old. ;)
npm, is there any particular reason you're still using PHP4?
npm 57
New Member
The server is from an outside company. I've contacted them about the possibility of an upgrade. Thank you all for your time, however in vain in turned out to be. :)
Ask them if there's any way you can install your own custom PHP. I'm on Dreamhost and they let users install their own version of PHP, it's not difficult, just a few files to copy and some changes to the .htaccess file. Ok, it's a little more complicated than that, but not much.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ram Laxman |
last post by:
Hi all,
I have a text file which have data in CSV format.
"empno","phonenumber","wardnumber"
12345,2234353,1000202
12326,2243653,1000098
Iam a beginner of C/C++ programming.
I don't know how to...
|
by: |
last post by:
Hi,
I need to read a big CSV file, where different fields should be converted to
different types,
such as int, double, datetime, SqlMoney, etc.
I have an array, which describes the fields and...
|
by: Douglas Crockford |
last post by:
There is a new version of JSON.parse in JavaScript. It is vastly
faster and smaller than the previous version. It uses a single call to
eval to do the conversion, guarded by a single regexp test to...
|
by: fyleow |
last post by:
I create a new Python file with the following using Wing IDE.
import feedparser
d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml")
print d.feed.title
I get this error when...
|
by: priyanka |
last post by:
Hi,
I was wondering if we could parse or do something in the executable(
whose source language was C). How can I use some scripting language
like perl/python to find out the information about...
| |
by: gs |
last post by:
let say I have to deal with various date format and I am give format string
from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
|
by: Perks |
last post by:
Hi.
I am trying to find out if it is possible to open a pdf file from
within PHP, and parse its contents in order to extract all form
fieldnames that might have been previously setup within the...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming.
FYI
Although I have called...
|
by: AdrianH |
last post by:
Assumptions
I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming.
FYI
Although I have called this...
|
by: MonkeeSage |
last post by:
A quick question about how python parses a file into compiled
bytecode. Does it parse the whole file into AST first and then compile
the AST, or does it build and compile the AST on the fly as it...
|
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,...
| |
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...
|
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,...
|
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...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |