•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 425,999 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,678 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2061 | Replies: 2
![]() |
•
•
Join Date: Aug 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I have installed apache 2.2.3 and PHP 5.1.5 on Win XP (IIS is also set up on different port) I have try the sample code from php.net; however, it keeps giving me error on opening the file please help.
[php]<?php
$file = "data.xml";
$depth = array();
function startElement($parser, $name, $attrs)
{
global $depth;
for ($i = 0; $i [ $depth[$parser]; $i++) {
echo " ";
}
echo "$name\n";
$depth[$parser]++;
}
function endElement($parser, $name)
{
global $depth;
$depth[$parser]--;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input"); //it keeps dying here~~
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>[/php]
Thank you in advance,
Pillow
[php]<?php
$file = "data.xml";
$depth = array();
function startElement($parser, $name, $attrs)
{
global $depth;
for ($i = 0; $i [ $depth[$parser]; $i++) {
echo " ";
}
echo "$name\n";
$depth[$parser]++;
}
function endElement($parser, $name)
{
global $depth;
$depth[$parser]--;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input"); //it keeps dying here~~
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>[/php]
Thank you in advance,
Pillow
Last edited by cscgal : Aug 23rd, 2006 at 1:02 am. Reason: Added [php] bbcode
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
Try moving your initial variables down to just before the block where they're defined. PHP doesn't support global variables as other languages do, so there's no reason to define something above function blocks.
(I'm not sure if this will solve it, but it might.)
(I'm not sure if this will solve it, but it might.)
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
•
•
Join Date: Aug 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I found out that the real problem is somehow i am not able to load any external files from php. My current setting is Apache 2.2.3 PHP5.15 on WinXP. Is there any setting I have to make to get it load an external file?
Thanks,
Thanks,
•
•
•
•
Try moving your initial variables down to just before the block where they're defined. PHP doesn't support global variables as other languages do, so there's no reason to define something above function blocks.
(I'm not sure if this will solve it, but it might.)
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
api asp blog blogger blogging code daniweb dell development dom drivers feed firefox games gdata google html intel internet linux microsoft mozilla news open open source open-source openoffice operating php programming reader red hat rss security software source standards sun super system ubuntu vista w3c weather web wesnoth windows xml xoap xp
- Read XML File in C/C++ (C++)
- [urgent] HTML form => XML file (JSP)
- Multiple Table Reading From An Xml File (VB.NET)
- could not open INSTALL.LOG file. (Windows NT / 2000 / XP / 2003)
- How to re-organized XML file and call XML file from my software (RSS, Web Services and SOAP)
- parsing error (XML file-java-schema) (Java)
- Pass XML file contents to a hash table. (Java)
Other Threads in the PHP Forum
- Previous Thread: Newsletter sending problems
- Next Thread: UPDATE query not working properly...


Linear Mode