473,738 Members | 4,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP4 XML DOM

Currently my web server supports only php4.
I want to know how to parse the xml and get the
element value using dom. I thought they have similar
function for getting element by id or tag name, so
far i haven't find anyting like that except fro PHP5 with
Domdocument. Any help is appreciated.
$dom = domxml_open_fil e ('data.xml');
$e_data = $dom->document_eleme nt();

<?xml version="1.0"?>
<book>
<title>hhelo</title>
</book>

Aug 17 '06 #1
3 8716

mich dobelman wrote:
Currently my web server supports only php4.
I want to know how to parse the xml and get the
element value using dom. I thought they have similar
function for getting element by id or tag name, so
far i haven't find anyting like that except fro PHP5 with
Domdocument. Any help is appreciated.
I heartily recommend upgrading to PHP5 and DOM extension,
it's much better than PHP4's DOM XML. Nevertheless, I hope
this helps:

$xml = '<?xml version="1.0"?>
<book>
<title>hhelo</title>
</book>' ;

// here we traverse shallowly all the children nodes of a
// given node and add node values of all the text nodes
// found to the result
function get_value ( $node )
{
$result = '' ;
$sub_nodes = $node -child_nodes ( ) ;
foreach ( $sub_nodes as $sub_node )
{
if ( $sub_node -node_type ( ) == XML_TEXT_NODE )
{
$result .= $sub_node -node_value ( ) ;
}
}
return ( $result ) ;
}

$doc = domxml_open_mem ( $xml ) ;

// method #1
// here we get all the <titleelement s in the document,
// then get the contents of the first one of them
$titles = $doc -get_elements_by _tagname ( 'title' ) ;
$result_1 = get_value ( $titles [ 0 ] ) ;

// method #2
// here we get the first element node child of the root
// element, then get its contents
$books = $doc -child_nodes ( ) ;
$book_ix = $title_ix = 0 ;
while ( $books [ $book_ix ++ ] -node_type ( ) !=
XML_ELEMENT_NOD E ) ;
$titles = $books [ -- $book_ix ] -child_nodes ( ) ;
while ( $titles [ $title_ix ++ ] -node_type ( ) !=
XML_ELEMENT_NOD E ) ;
$result_2 = get_value ( $titles [ -- $title_ix ] ) ;

// method #3
// the same thing, only using XPath
$xpath = $doc -xpath_new_conte xt ( ) ;
$result =
$xpath -xpath_eval ( '//book/title/text()' ) ;
$result_3 = $result -nodeset [ 0 ] -content ;

--
Pavel Lepin

Aug 17 '06 #2
Thanks, Pavel
>$doc = domxml_open_mem ( $xml ) ;
The function you provided works perfectly for local file, but
not the remote one. Do i have to use the different function remote
file?

about PHP5
I want to, but My ISP said not ready to upgrade to PHP5.

Aug 17 '06 #3

Shuan wrote:
$doc = domxml_open_mem ( $xml ) ;

The function you provided works perfectly for local file,
but not the remote one. Do i have to use the different
function remote file?
Actually, domxml_open_mem () parses XML from a string. For
both local and remote files you should use
domxml_open_fil e() - well, depending on your definition of
'remote' and your ISP's PHP settings ('allow_url_fop en').
The following should work:

$doc = domxml_open_fil e
( 'http://example.org/dir/data.xml' ) ;

--
Pavel Lepin

Aug 18 '06 #4

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

Similar topics

0
2466
by: Nisha_tm | last post by:
Hello: I have a form in which I have checkboxes. Right now, I wrote the form's html and the php4 script. I use associative arrays in the form to capture the checkboxes that are checked. My html form puts the data in $info if the check box is checked. Part of my php4 script is as follows:
0
2042
by: Klaus Boehmer | last post by:
Hello, I'm trying to install gd2 with gif-support as an extension with php4. I compiled the patched version of gd2 - fine. I compiled php4 with gd=shared - fine. I installed it and restarted apache and I get: undefined symbol: gdImagePngCtx I recompiled php4 and included gd and everything works fine. But as soon as I compile gd2 as shared things mess up. I've searched 2 days for a solution, but didn't find anything. Please help me!
1
2088
by: Erik | last post by:
I understand, that PHP4 has a MySQL client built in. I was warned, that this client does not support the MySQL 4.1.1 system, which I installed on my RH9 box end that I need to install that version myself in PHP4. Now how do I install that MySQL client in my PHP4 ? Or is is easier/smarter to use another MySQL version, one that IS supported directly by PHP4 ?
5
2801
by: Tim Tyler | last post by:
I'm sure this is a FAQ - but I could not find a coherent statement of the answer: Some of my clients want PHP4. Other ones want PHP5. Can I run both PHP4 and PHP5 under the same instance of Apache - both on port 80 - using different file extensions to distinguish between them? --
0
2019
by: Dave Pham | last post by:
I just cleaned my comp, and I am trying to re-config my webserver... I am trying to setup apache 2 so it runs both php4 and php5, I also have two instances of mysql running. I know this can be done cos it had work before, but after this incident its not longer... These are my directories for each: Apache: D:\ServerRoot\Apache\Apache2 MySQL1: D:\ServerRoot\mysql1
1
1972
by: porneL | last post by:
I've had setup on WinXP: Apache1.3 with PHP4 module and PHP5 installedas CGI for one vhost. This worked fine, till I installed Zend Studio 4 beta. I'm trying to make Zend Server use my existing configuration, but without success. If I point it to PHP4 php.ini, PHP cannot find (or rather refuses to load) modules. If I point it to PHP5 php.ini, I cannot enter server console, because my php lacks ZendOptimizer
2
2587
by: Stefan Huber | last post by:
Hi I've got a really strange problem, and can't find out why it's not working as intended. in order to use php4 and 5 together on a webserver and the requirement for running as different users, I use suexec and a wrapper script for php files. to make it a bit clearer, i'll post the different snippets: httpd.conf:
12
2303
by: Drazen Gemic | last post by:
How long will PHP4 be supported ? When is PHP4 end of life scheduled ? DG
3
2946
by: doctorhardik | last post by:
hai all i am try configure php4.3.9 on my FC-3 machine. and my mysql database version 5.0.1, in phpinfo file it show mysql but when i run php -v command it show error like
8
2318
by: FFMG | last post by:
Hi, I am slowly moving my code to php5. But I would like to make it backward compatible in case something bad happens, (and to make sure I understand what the changes are). The way the constructors work seem to have changed quite a bit and I am not getting the same behavior across the versions. // Some simple code/
0
8969
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
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
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
9208
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...
0
6053
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
4570
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
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
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.