473,809 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetElementById PHP5 DOM Problem

When the data structure looks like this:

<page>
<point id="1">
<premise> 1+1=2 </premise>
</point>
<point id="2">
<premise> round is better than square </premise>
</point>
<thought id="1">
<note> I like Fridays </note>
</thought>
<thought id="2">
<note> rsaturday's rock </note>
</thought>
</page>

how do i use GetElementById( ) to get thought id 2's note?

i saw some examples where the id was unique within the xml. in my
case, though, the id isn't unique and i couldn't google up a single
example. te syntax isn't intuitive to me so i haven't been able to
work it out on my own, either.

tia...
tia...

Feb 22 '06 #1
4 2031


Skeets wrote:
When the data structure looks like this:

<page>
<point id="1">
<premise> 1+1=2 </premise>
</point>
<point id="2">
<premise> round is better than square </premise>
</point>
<thought id="1">
<note> I like Fridays </note>
</thought>
<thought id="2">
<note> rsaturday's rock </note>
</thought>
</page>

how do i use GetElementById( ) to get thought id 2's note?


getElementById on XML is only going to work if there is a DTD that
defines the attributes of type ID. And ID attribute values are required
to be unique in the document. And ID attribute values have to begin with
a letter so your values starting with/consisting of a digit are not
valid ID values.

I guess you could use XPath to look for point elements with @id being 2 e.g.
/page/thought[@id = '2']/note/text()
with PHP 5

$xPathEvaluator = new DOMXPath($xmlDo cument);
$nodeList = $xPathEvaluator->query(
"/page/thought[@id = '2']/note/text()", $xmlDocument);
foreach ($nodeList as $node) {
echo $node->data . "<br>\r\n";
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 22 '06 #2
Thanks Martin.

i'm receiving an error when tryiong to use xpath.

i used the example here:

http://us2.php.net/manual/en/functio...expression.php

i cipied and pasted it and it get the following error:

PHP Fatal error: Call to undefined function domxml_open_mem () in
C:\web\html\dmt \_debug_tmp.php on line 497

Feb 23 '06 #3


Skeets wrote:

i'm receiving an error when tryiong to use xpath.
I think you said you use PHP 5. My earlier post contains an example that
works with PHP 5.
i used the example here:

http://us2.php.net/manual/en/functio...expression.php

i cipied and pasted it and it get the following error:

PHP Fatal error: Call to undefined function domxml_open_mem () in
C:\web\html\dmt \_debug_tmp.php on line 497


That stuff is part of a PHP 4 only extension for DOM and XPath. You
can't use that with PHP 5 and you really don't want to.
If you are using PHP 4 now and want to use that code then you need to
make sure that DOM XML extension for PHP 4 is installed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 23 '06 #4
Martin, for some reason i was having lots of trouble.

i eventually found out how to do everything i needed, and more, in
PHP5's simplexml.

this tutorial is excellent:

http://www.isolated-designs.net/core...xpath-in-php-5

the author switched from

simplexml_load_ file('applicati ons.xml');

to

$apps = simplexml_load_ string($xml);

midstream - with no comment. for the newbs, you only need one or the
other - depending on if you are importing a file or working with a
string (included from another file or actually in the same file).

back to my problem, the solution is as simple as:

<?php
$page = simplexml_load_ string($xml_str ing);
$thought = $page->xpath("//thought[@id = 2]");
echo $thought[0]->note;
?>

this should print the note, although i don't have time to test this
code. i did test the code in the tutorial and it worked liked a charm.

thanks for helping - i'm not sure what i was doing to gaff things, but
this method is the simplest around. being a newb, i like that a lot.

Feb 23 '06 #5

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

Similar topics

7
3700
by: Christoph Nothdurfter | last post by:
Hallo! I was wondering if my PHP4-Scripts will run under PHP5 (Haeven't tried the beta yet). Does anybody know? Thank you, -Christoph
6
4593
by: somaBoy MX | last post by:
I'm configuring PHP5 on my WinXP pro machine as an Apache2 handler. However when I start apache I get system errormessages like "PHP Shutdown: Unable to load dynamic library 'c:\php\ext\php_mcrypt.dll'" for all the extensions I enabled. I have verified that the extensions indeed exist in this directory, I've changed extension_dir accordingly and I've copied them to my Windows/system32 directory. What's going on?
1
3537
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting my applications to PHP5 and I've stumbled on yet another problem. I'll try to simplify things a bit. I have a main script that is being executed (index.php, PHP5 script) and that is including 2 other files: config.inc (PHP5 script, for the configuration) and adodb.inc.php (PHP4 script, ADOdb functionality, though it could be any other PHP4 script). On php.ini, error_reporting = E_ALL|E_STRICT. These are...
0
1606
by: Joe | last post by:
Hey everyone I'm trying to use php to extract data from an AS/400 system. The php engine is running locally on my workstation(win2000) and I'm accessing the DB2 database on the AS/400 system via ODBC from my workstation. It worked in an previous installation using a dated version of php (4.something.something, can't remember), but since I upgrated to php5 my PEAR DB module tells me I can't connect.
4
1831
by: Daniel Andersen | last post by:
Hey, We are in the process of rewriting our internal management system (which was written in PHP4), and figured this would be a good time to migrate to PHP5 to get all the OO goodness it has to offer :) I am running php 5.0.3 on apache 1.3.something under slackware linux. Unfortunately I frequently get segfaults from php scripts, and they are not even scripts that do anything fancy or special. For example, in one script i got a...
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:
2
2276
by: mananvyas | last post by:
Hi, I am working on PHP5 and all the xmldom related extensions are installed and on properly. I am trying to execute following code but some how not working. $doc = new DomDocument(); $doc->validateOnParse = true; $doc->load('abc.xml');
0
2006
by: cty | last post by:
Title: Problem in session using php5 Good day, I use php5+mySQL4+IIS5.x Previuosly i use php4 and no error occur,
3
3307
by: xhe | last post by:
I have just upgraded my php version form php4 to php5. and I met this problem, and don't know if you know the solution. My site was written in PHP4, and most parts can be running smoothly in PHP5, only that in old version, I can use $row to access the data in database directly, no need to put double quote around fieldname. BUT in PHP5, this is wrong, I got error message "undefined constant". I know this is because PHP5 see the fieldname...
0
9721
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
9603
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,...
0
10376
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
10387
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
10120
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
9200
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
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();...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.