Page 1 of 1
domxml_open_mem function
Posted: Thu Jun 19, 2003 1:40 pm
by jtse
Hi,
I am new here and I just began to learn DOM and PhP.
I wrote this small program in php version 4.3.1
Code: Select all
<?php
if (!$doc=domxml_open_mem("xml/cd_catalog.xml")){
echo "Error while parsing";
exit;
}
$root = $doc->document_element();
print ("The name of the root element is : " . $root->tagname . "<br />");
?>
On running this program, I received this error msg "Fatal error: Call to undefined function: domxml_open_mem() on line 2".
I appreciate if anyone could suggest me a way to work around with this problem.
John
Posted: Thu Jun 19, 2003 1:50 pm
by cactus
You will need to check that you have:
a) installed the correct libs:
PHP Man wrote:Requirements
This extension makes use of the GNOME XML library. Download and install this library. You will need at least libxml-2.4.14. To use DOM XSLT features you can use the libxslt library and EXSLT enhancements from
http://www.exslt.org/. Download and install these libraries if you plan to use (enhanced) XSLT features. You will need at least libxslt-1.0.18.
b) compiled support for the DOM extensions:
PHP Man wrote:Installation
This extension is only available if PHP was configured with --with-dom[=DIR]. Add --with-dom-xslt[=DIR] to include DOM XSLT support. DIR is the libxslt install directory. Add --with-dom-exslt[=DIR] to include DOM EXSLT support, where DIR is the libexslt install directory.
Ref:
http://uk.php.net/manual/en/ref.domxml.php
Try creating a
phpinfo() page to check that you have these installed.
Regards,
Posted: Thu Jun 19, 2003 4:09 pm
by jtse
Hi Cactus,
Thks for your info.
I have installed the GNOME XML library and added this "--with-dom = 'C:\libxml2-2.5.7' " in my php.ini file. Then I reboot Apache and ran the php_info, I am not sure where do I look for this info. I browsed thro' the whole page and could not find it.
Is there anything that I missed?
Regards,
John
Posted: Thu Jun 19, 2003 4:27 pm
by cactus
Apologies, I should have enquired about your configuration.
Since you are using Windows you will need to take note of this part of the PHP manual:
PHP Man wrote:Note to Win32 Users: In order to enable this module on a Windows environment, you must copy one additional file from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32). For PHP <= 4.2.0 copy libxml2.dll, for PHP >= 4.3.0 copy iconv.dll from the DLL folder to your SYSTEM32 folder.
Ref:
http://uk.php.net/manual/en/ref.domxml.php
Because of this you won't need the GNOME XML libs, they are for *nix (Linux etc) systems and won't work on your platform.
Return your php.ini to it's previous state (remove the "--with-dom = 'C:\libxml2-2.5.7'), and have a look at the manual page below to see how you can enable your DOM extensions:
Ref :
Installation of Windows extensions
Regards,
Posted: Fri Jun 20, 2003 10:26 am
by jtse
Cactus,
Once again thank you for your direction.
It works fine now. But one funny thing is it only works well with the domxml_open_file but not the domxml_open_mem function.
For your reference, the contents in the xml file are as follows:
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
</CATALOG>
The error msgs I received on running with domxml_open_mem are
Warning: domxml_open_mem() [function.domxml-open-mem]: Entity: line 1: in C:\Program Files\Apache Group\Apache2\htdocs\swnotion\mine\jt_dom.php on line 9
Warning: domxml_open_mem() [function.domxml-open-mem]: error: in C:\Program Files\Apache Group\Apache2\htdocs\swnotion\mine\jt_dom.php on line 9
Warning: domxml_open_mem() [function.domxml-open-mem]: Start tag expected, '<' not found in C:\Program Files\Apache Group\Apache2\htdocs\swnotion\mine\jt_dom.php on line 9
Warning: domxml_open_mem() [function.domxml-open-mem]: jt_xml/jt_cd_catalog.xml in C:\Program Files\Apache Group\Apache2\htdocs\swnotion\mine\jt_dom.php on line 9
Warning: domxml_open_mem() [function.domxml-open-mem]: ^ in C:\Program Files\Apache Group\Apache2\htdocs\swnotion\mine\jt_dom.php on line 9
Fatal error: Call to a member function on a non-object in C:\Program Files\Apache Group\Apache2\htdocs\swnotion\mine\jt_dom.php on line 10
Any suggestions?
Regards
Posted: Fri Jun 20, 2003 12:37 pm
by cactus
My only concern here is with the use of Apache 2, while I have no specific details to give you I feel the version of PHP you are using with Apache 2 may have issues.
I have no experience of the latest versions of PHP/Apache, I tend to stick to trusted/stable releases.
You could try (but tend not to recommend) upgrading to PHP 4.3.2, which I'm lead to believe is more compatible with Apache 2 than ever before, but that's from a Linux perspective. I only suggest this if the server/machine you are using is classed as development and won't impact any of your other systems/users etc. (please don't shoot me if it goes belly up!)
Have you posted your entire code to this thread ? If not can you post it, just refresh my memory
Also, have you tried (as a test) passing your XML document as a string, instead of the domxml_open_mem() doing the readfile etc ?
You will need to single quote the string and then pass that to the domxml_open_mem() method.
EG:
Code: Select all
$xml_string = implode('', file("test.xml"));
$doc = domxml_open_mem($xml_string);
I best stop, I'm just guessing now
Regards,
Posted: Fri Jun 20, 2003 1:32 pm
by volka
Posted: Fri Jun 20, 2003 2:33 pm
by cactus
Apologies, I was infiring that in my rather cryptic ending mesage, sorry jtse, I should have been a little clearer!
Cheers volka, for decrypting my madness
Regards,
Posted: Fri Jun 20, 2003 7:57 pm
by jtse
Thks guys for the tips.
But could I ask how/when do I use the domxml_open_mem()? Both domxml_open_file() and domxml_open_mem() parse the xml document and look almost the same thing to me. This could be a dumb or silly question?
Regards
Posted: Sat Jun 21, 2003 6:51 am
by cactus
If you have another process that creates an XML document, instead of writing that out as a file and then reopening it with the domxml_open_file(), you can use the domxml_open_mem() to parse your XML string into a XML Tree, just a quicker way to parse your XML without the file handle.
Regards,