473,565 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml xquery and php

I am new to XML. Initially I was saving all the settings in either PHP
or text files or database tables and use to parse the config variables
from files or query from the database. Now I want to keep all the
settings in the XML file and get the setting values, user datas (as
database is not involved and all the results are stored in XML file
itself) from it.

Referring to http://www.w3schools.com/xquery/xquery_example.asp, it
gives sample xml file and also query. But I don't know how to execute
it.
-------------------------------------------------------------------------------------------------------------

"books.xml" :

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book category="COOKI NG">
<title lang="en">Every day Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="CHILD REN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

<book category="WEB">
<title lang="en">XQuer y Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyan athan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="WEB">
<title lang="en">Learn ing XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>

-------------------------------------------------------------------------------------------------------------

doc("books.xml" )/bookstore/book[price<30]

The XQuery above will extract the following:

<book category="CHILD REN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

-------------------------------------------------------------------------------------------------------------

I have a PHP 5 installed on the computer. I want to know, provided the
XML file, how do I execute the query and get the results. Are there
some API, Packages avaailable.

Thanks.

Manish

Jul 17 '06 #1
2 3729


Manish wrote:

doc("books.xml" )/bookstore/book[price<30]

The XQuery
I have a PHP 5 installed on the computer. I want to know, provided the
XML file, how do I execute the query and get the results. Are there
some API, Packages avaailable.
PHP 5 does not support XQuery, and XQuery is not yet a W3C recommendation.
PHP supports XPath 1.0 however so using the DOM and XPath support in PHP
5 you can do e.g.

<?php
$xmlDocument = new DOMDocument();
if ($xmlDocument->load('file.xml ')) {
$xpath = new DOMXPath($xmlDo cument);
$nodeList = $xpath->query('/bookstore/book[price<30]', $xmlDocument);
header('Content-Type: text/plain');
foreach ($nodeList as $node) {
echo $xmlDocument->saveXML($nod e) . "\r\n";
}
}
?>

Setting Content-Type as text/plain and simply echoing the XML to the
user agent is probably not what you want to do in a real application but
it allows you to see the XML of the nodes the XPath selection returned
for that sample above.

See the PHP documentation
<http://www.php.net/manual/en/function.dom-domxpath-query.php>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 17 '06 #2
Hi Martin,

Thanks for the Post. It worked. As I am new to XML, I will need to
study the topic and figure out the syntax format for inserting new
data, update, and delete the information in the XML file.

Regards.

Manish

Jul 18 '06 #3

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

Similar topics

2
2781
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now wondering if I am better of learning XQuery instead? Any thought and opinions would be appreciated. Cheers - Tom. The Architect: "Hope, it is the...
0
1410
by: Benjamin G. Jones | last post by:
I am having a very basic problem with XQuery. I want to use an XQuery API in Java (either Saxon or Qexo), and I have an XQuery expression that works as expeced from the command line if I specify a filename before the xpath expression. What I want to know is this: If I want to use Qexo's gnu.xquery.lang.XQuery.eval() or Saxon's...
1
2035
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the following sample document: <root> <a b="1" />
4
4112
by: Jeff Kish | last post by:
Hi. I see it appears that xquery is case senstitive for looking for particular attribute values etc. Is there a standard way around this? Say I want to see all nodes with an attribute valued "copyright" or some such? Finally, is there a "like" function similar to sql? I perused the docs and did not see anything, but was wondering if I...
0
2162
by: Tony Lavinio | last post by:
Dear Stylus Studio Friends, The new year is scarcely one month old, but we already have lots to report! For starters, there's Stylus Studio 6 Release 2. The latest release of Stylus Studio boasts literally hundreds of product enhancements, and is available now for free trial download. We're also proud to present our interview with Dr....
0
1470
by: Tony Lavinio | last post by:
Dear comp.text.xml community, Microsoft recently announced that they are dropping XQuery from their next release of the .NET Framework, 2.0 (Whidbey). Since Microsoft ships .NET Framework only every 3 or so years, cutting XQuery from Whidbey means that the next opportunity for XQuery to find its way into .NET Framework won't be until around...
0
2294
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies (http://www.datadirect.com), the software industry leader in standards-based components for connecting applications to data and an operating unit of Progress...
8
3187
by: Clamps | last post by:
So I've been reading about XQuery, but cannot find a dll or namespace download to use the technology in vs.net 2002 or 2003. Any directions would be great. -- "If I'm the president, we're going to have emergency-room care, we're going to have gag orders." ---W "The President"
2
1576
by: Ale | last post by:
Hi all! I need to build a middleware for XQuery: I mean a software receiving a std xquery and outputting the xquery result on "database.xml". This middleware must use 7 or 8 different choosable XQuery implementations... The XQuery received must be std for all implementations. The middleware will parse the std XQuery in the specific XQuery...
2
4309
by: tammo.mueller | last post by:
Hi, I'm trying to execute a xquery statement and I get always errors. It seems that only the prolog section is giving me errors. If I want to declare a namespace the xquery processor is coming up with an "unexpected token" error. The same error appears if I just set the version. The xquery statement itself is working without prolog, but...
0
7666
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...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
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...
0
7951
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...
1
5484
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...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.