473,378 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="CHILDREN">
<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">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="WEB">
<title lang="en">Learning 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="CHILDREN">
<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 3716


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($xmlDocument);
$nodeList = $xpath->query('/bookstore/book[price<30]', $xmlDocument);
header('Content-Type: text/plain');
foreach ($nodeList as $node) {
echo $xmlDocument->saveXML($node) . "\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
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...
0
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...
1
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...
4
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...
0
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...
0
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...
0
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...
8
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...
2
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.