473,625 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does this not parse xml?

57 New Member
Here's the sample xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <menu>
  3.     <entry>
  4.         <action>
  5.             Test
  6.         </action>
  7.         <title>
  8.             Test Menu Item 1
  9.         </title>
  10.     </entry>
  11.     <entry>
  12.         <action>
  13.             Test 2
  14.         </action>
  15.         <title>
  16.             Test Menu Item 2
  17.         </title>
  18.     </entry>
  19. </menu>
And here's the php code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dom = new DOMDocument();
  3. $dom->load("menu.xml");
  4. $menu = new domxpath($dom);
  5. foreach($menu->query("//menu/entry") as $entry) {
  6.     echo "Action is: " . $menu->query('.//action',$entry)->item(0)->nodeValue;
  7.     echo "Title is: " . $menu->query('.//title',$entry)->item(0)->nodeValue;
  8. }
  9. ?>
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!
Jan 27 '11 #1
18 1589
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
Jan 27 '11 #3
Markus
6,050 Recognized Expert Expert
Code Green, I don't see it?
Jan 27 '11 #4
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.
Jan 27 '11 #5
Markus
6,050 Recognized Expert Expert
I'm struggling to spot the syntax error, also.

And you're using PHP4? Seriously? It's 2011!
Jan 27 '11 #6
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!
Jan 27 '11 #7
code green
1,726 Recognized Expert Top Contributor
Can I stop what seems to be a misunderstandin g.
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
Jan 28 '11 #8
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?
Jan 28 '11 #9
npm
57 New Member
Sorry, just for clarification, here's a visual of what I changed it to:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dom = new DOMDocument();
  3. $dom->load("xml.xml");
  4. $menu = new DOMXPath($dom);
  5. foreach($menu->query("//menu/entry") as $entry) {
  6.     print "Action is: " . $menu->query('.//action',$entry)->item(0)->nodeValue;
  7.     print "Title is: " . $menu->query('.//title',$entry)->item(0)->nodeValue;
  8. }
  9. ?>
Jan 28 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

22
872
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 tokenize the comma separated values.I used strtok function reading line by line using fgets.but it gives some weird behavior.It doesnot stripout the "" fully.Could any body have sample code for the same so that it will be helfful for my...
24
3154
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 their types. I would like to somehow store a reference to parsing operations in this array (such as Int32.Parse, Double.Parse, SqlMoney.Parse, etc), so I can invoke the appropriate one without writing a long switch.
8
10405
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 assure that it is safe. JSON.parse = function (text) { return (/^(\s|]|"(\\|)*"|-?\d+(\.\d*)?(?\d+)?|true|false|null)+$/.test(text)) && eval('(' + text + ')'); };
4
1879
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 I debug. AssertionError:
34
2963
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 the executable ? Is it possible ? Also, how does the compiler add inling to the program ? I know that whenever it sees"inline" in front of the procedure name, it inlines it. But if we give the -finline options, it inline all the procedures ? How
29
2884
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
7
14150
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 pdf itself. I want to find this out so that I can then generate a HTML form with all required questions, which when submitted, will generate a fdf / xfdf file, using the techniques from the following tutorial
5
64615
AdrianH
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
1
64087
AdrianH
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
11
2696
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 reads expressions? (If the former case, why can't functions be called before their definitions?) Thanks, Jordan
0
8256
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
8189
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8356
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
8497
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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
4089
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1500
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.