473,789 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML create with PHP 5 help

I need to create an XML string using PHP5. The examples I have followed seem to
be using out dated libary calls. I tried new_xmldoc() and new DomDocument.
Both get undefined errors. How do I create an XML string where it will look
something like this:

<response>
<data>
<parts>
<part>
<number>bla</number>
<price>9999</price>
<uom>EA</uom>
<locations>
<location>
<id>bla</id>
<qty>9999</qty>
</location>
</locations>
</part>
</parts>
</data>
</response>

Thanks
Gary Quiring

Jul 17 '05 #1
13 6677
You just echo it out to the browser like that, and send the XML content
header.

(Or save it into a variable, for storing into a file)

eg:

<?php
header("Content-type: text/xml");
echo "
<response>\n
<data>\n
<parts>\n
<part>\n
<number>bla</number>\n
</part>\n
</parts>\n
</data>\n
</response>";
?>
"Gary Quiring" <gq******@msn.c om> wrote in message
news:5e******** *************** *********@4ax.c om...
I need to create an XML string using PHP5. The examples I have followed
seem to
be using out dated libary calls. I tried new_xmldoc() and new
DomDocument.
Both get undefined errors. How do I create an XML string where it will
look
something like this:

<response>
<data>
<parts>
<part>
<number>bla</number>
<price>9999</price>
<uom>EA</uom>
<locations>
<location>
<id>bla</id>
<qty>9999</qty>
</location>
</locations>
</part>
</parts>
</data>
</response>

Thanks
Gary Quiring

Jul 17 '05 #2
On Tue, 17 May 2005 14:24:19 +0100, "Alistair Baillie SS2002"
<ab******@cis.s trath.ac.uk> wrote:
You just echo it out to the browser like that, and send the XML content
header.

(Or save it into a variable, for storing into a file)

eg:

<?php
header("Conten t-type: text/xml");
echo "
<response>\n
<data>\n
<parts>\n
<part>\n
<number>bla</number>\n
</part>\n
</parts>\n
</data>\n
</response>";
?>

My output string will vary on the input I need to respond to. That kind of
creation makes it difficult to modify and add childs.
Jul 17 '05 #3
Assumint that the XML output will be approximatly the same, just use for
loops, to add the varying lengths.

IF you mean it will be totally different you could use 3Dimensional arrays,
and then generate the XML string from that.

other than these 2 methods, I'm afraid I cant help you. sorry.

Example for creating RSS output (not using 3d arrays):
<?php
/****
* Blog Off.net
*
* @author: Alistair Baillie
* @website: http://www.alistairbaillie.co.uk
* @version: 1.0
* @sourcepath: \\BO\
*
* The contents of this file and any associated files, including but in no
way
* limited to artwork and images, are copyright (c) 2005 Alistair D Baillie
* Any unauthorised reproduction or distribution is strictly prohibbited!
****/

$_BLOGOFF = true;

require("includ es/comon.php");
header("Content-type: text/xml");

// Catch default blog request :)
if ( $_REQUEST['id'] == 0 ) {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Blog Off.net</title>
<link>http://www.blogoff.net/</link>
<description>Th e 5 latest postings to Blog Off.net Journals</description>
<language>en-gb</language>

<?php
$query = $db->query("SELEC T blogs_id, blogs_datetime, blogs_userid,
blogs_title, blogs_entry,
(SELECT Count(*) FROM bo_comments WHERE comments_blogid =row_x.blogs_id ) as
numComments,
users_displayna me FROM bo_blogs row_x, bo_users WHERE ( blogs_private=0
AND blogs_published =1 AND
users_id=blogs_ userid )
ORDER BY blogs_datetime DESC LIMIT 5");

if ( $db->numrows( $query ) > 0 ) {
while ( $theData = $db->fetchrow( $query ) ) {
?>
<item>
<title><?php echo stripslashes( $theData['blogs_title'] ); ?></title>
<link>http://www.blogoff.net/index.php?bpost =<?php echo
$theData['blogs_id']; ?></link>
<description><? php echo stripslashes( $theData['blogs_entry'] );
?></description>
<dc:creator><?p hp echo stripslashes( $theData['users_displayn ame'] );
?></dc:creator>
<dc:date><?ph p echo date("Y-m-d", $theData['blogs_datetime ']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}

if ( $_REQUEST['id'] > 0 ) {
$id = addslashes($_RE QUEST['id']);
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Blog Off.net</title>
<link>http://www.blogoff.net/</link>
<description>Th e 5 latest postings to this persons blog!</description>
<language>en-gb</language>

<?php
$query = $db->query("SELEC T blogs_id, blogs_datetime, blogs_userid,
blogs_title, blogs_entry,
(SELECT Count(*) FROM bo_comments WHERE comments_blogid =row_x.blogs_id )
as numComments,
users_displayna me FROM bo_blogs row_x, bo_users WHERE ( blogs_private=0
AND blogs_published =1 AND
users_id=blogs_ userid AND blogs_userid='$ id' )
ORDER BY blogs_datetime DESC LIMIT 5");

if ( $db->numrows( $query ) > 0 ) {
while ( $theData = $db->fetchrow( $query ) ) {
?>
<item>
<title><?php echo stripslashes( $theData['blogs_title'] ); ?></title>
<link>http://www.blogoff.net/index.php?bpost =<?php echo
$theData['blogs_id']; ?></link>
<description><? php echo stripslashes( $theData['blogs_entry'] );
?></description>
<dc:creator><?p hp echo stripslashes( $theData['users_displayn ame'] );
?></dc:creator>
<dc:date><?ph p echo date("Y-m-d", $theData['blogs_datetime ']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}
?>
Jul 17 '05 #4
Ok, I have done some searching, the new_xmldoc() function was never a valid
PHP function, but it appears to be part of the ZEND Library

See: http://www.zend.com/phpfunc/function.xmldoc.php

"Alistair Baillie SS2002" <ab******@cis.s trath.ac.uk> wrote in message
news:42******** @nntphost.cis.s trath.ac.uk...
Assumint that the XML output will be approximatly the same, just use for
loops, to add the varying lengths.

IF you mean it will be totally different you could use 3Dimensional
arrays, and then generate the XML string from that.

other than these 2 methods, I'm afraid I cant help you. sorry.

Example for creating RSS output (not using 3d arrays):
<?php
/****
* Blog Off.net
*
* @author: Alistair Baillie
* @website: http://www.alistairbaillie.co.uk
* @version: 1.0
* @sourcepath: \\BO\
*
* The contents of this file and any associated files, including but in no
way
* limited to artwork and images, are copyright (c) 2005 Alistair D Baillie
* Any unauthorised reproduction or distribution is strictly prohibbited!
****/

$_BLOGOFF = true;

require("includ es/comon.php");
header("Content-type: text/xml");

// Catch default blog request :)
if ( $_REQUEST['id'] == 0 ) {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Blog Off.net</title>
<link>http://www.blogoff.net/</link>
<description>Th e 5 latest postings to Blog Off.net Journals</description>
<language>en-gb</language>

<?php
$query = $db->query("SELEC T blogs_id, blogs_datetime, blogs_userid,
blogs_title, blogs_entry,
(SELECT Count(*) FROM bo_comments WHERE comments_blogid =row_x.blogs_id )
as numComments,
users_displayna me FROM bo_blogs row_x, bo_users WHERE ( blogs_private=0
AND blogs_published =1 AND
users_id=blogs_ userid )
ORDER BY blogs_datetime DESC LIMIT 5");

if ( $db->numrows( $query ) > 0 ) {
while ( $theData = $db->fetchrow( $query ) ) {
?>
<item>
<title><?php echo stripslashes( $theData['blogs_title'] ); ?></title>
<link>http://www.blogoff.net/index.php?bpost =<?php echo
$theData['blogs_id']; ?></link>
<description><? php echo stripslashes( $theData['blogs_entry'] );
?></description>
<dc:creator><?p hp echo stripslashes( $theData['users_displayn ame'] );
?></dc:creator>
<dc:date><?ph p echo date("Y-m-d", $theData['blogs_datetime ']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}

if ( $_REQUEST['id'] > 0 ) {
$id = addslashes($_RE QUEST['id']);
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Blog Off.net</title>
<link>http://www.blogoff.net/</link>
<description>Th e 5 latest postings to this persons blog!</description>
<language>en-gb</language>

<?php
$query = $db->query("SELEC T blogs_id, blogs_datetime, blogs_userid,
blogs_title, blogs_entry,
(SELECT Count(*) FROM bo_comments WHERE comments_blogid =row_x.blogs_id )
as numComments,
users_displayna me FROM bo_blogs row_x, bo_users WHERE ( blogs_private=0
AND blogs_published =1 AND
users_id=blogs_ userid AND blogs_userid='$ id' )
ORDER BY blogs_datetime DESC LIMIT 5");

if ( $db->numrows( $query ) > 0 ) {
while ( $theData = $db->fetchrow( $query ) ) {
?>
<item>
<title><?php echo stripslashes( $theData['blogs_title'] ); ?></title>
<link>http://www.blogoff.net/index.php?bpost =<?php echo
$theData['blogs_id']; ?></link>
<description><? php echo stripslashes( $theData['blogs_entry'] );
?></description>
<dc:creator><?p hp echo stripslashes( $theData['users_displayn ame'] );
?></dc:creator>
<dc:date><?ph p echo date("Y-m-d", $theData['blogs_datetime ']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}
?>

Jul 17 '05 #5
Gary Quiring wrote:
I need to create an XML string using PHP5. The examples I have
followed seem to be using out dated libary calls. I tried
new_xmldoc() and new DomDocument. Both get undefined errors. How do
I create an XML string where it will look something like this:


<snip>

http://www.zend.com/php5/articles/php5-xmlphp.php

However, the undefined errors seem that for some reason you don't have the
DOM extension in your PHP installation. What version of PHP5 do you use?

Berislav
Jul 17 '05 #6
On Wed, 18 May 2005 09:08:38 +0200, "Berislav Lopac"
<be************ @lopsica.com> wrote:
Gary Quiring wrote:
I need to create an XML string using PHP5. The examples I have
followed seem to be using out dated libary calls. I tried
new_xmldoc() and new DomDocument. Both get undefined errors. How do
I create an XML string where it will look something like this:


<snip>

http://www.zend.com/php5/articles/php5-xmlphp.php

However, the undefined errors seem that for some reason you don't have the
DOM extension in your PHP installation. What version of PHP5 do you use?

Berislav

PHP 5.04

I did configure with dom support. Did I do it wrong?

Here is the php info:

System Linux ae1 2.6.9-1.667smp #1 SMP Tue Nov 2 14:59:52 EST 2004 i686
Build Date May 13 2005 15:24:06
Configure Command './configure' '--with-informix=/opt/informix'
'--with-apxs2=/usr/sbin/apxs' '--with-config-file-path=/etc'
'--enable-force-cgi-redirect' '--enable-pic' '--enable-inline-optimization'
'--with-bz2' '--with-curl' '--enable-soap' '--with-dom' '--with-gettext'
'--with-ncurses' '--with-gmp' '--with-iconv' '--with-layout=GNU'
'--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes'
'--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm'
'--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp'
'--enable-wddx' '--without-oci8' '--with-imap=shared' '--with-imap-ssl'
'--with-kerberos' '--with-ldap=shared' '--enable-memory-limit' '--enable-bcmath'
'--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx'
'--enable-dio' '--enable-mcal'


Jul 17 '05 #7
Try the following Dom syntax:
And try to put some of your own stuff in it.
/* Dom document */
$dom = new DOMDocument("1. 0","iso-8859-1");
/* Create all elements */
$response = $dom->createElement( "response") ; //root element
$data = $dom->createElement( "data");
$parts = $dom->createElement( "parts");
$part = $dom->createElement( "parts");
$number = $dom->createElement( "number","bla") ;
$price = $dom->createElement( "price", "9999");

/* Now place them in the correct place in the tree */

$response->appendChild($d ata);
$data->appendChild($p arts);
$parts->appendChild($p art);
$part->appendChild($n umber);
$part->appendChild($p rice);

$dom->appendChild($r esponse);

echo $dom->saveXML();
Jul 17 '05 #8
On Wed, 18 May 2005 15:14:36 +0200, Azeus <IF************ *************@M P.com>
wrote:
Try the following Dom syntax:
And try to put some of your own stuff in it.
/* Dom document */
$dom = new DOMDocument("1. 0","iso-8859-1");
/* Create all elements */
$response = $dom->createElement( "response") ; //root element
$data = $dom->createElement( "data");
$parts = $dom->createElement( "parts");
$part = $dom->createElement( "parts");
$number = $dom->createElement( "number","bla") ;
$price = $dom->createElement( "price", "9999");

/* Now place them in the correct place in the tree */

$response->appendChild($d ata);
$data->appendChild($p arts);
$parts->appendChild($p art);
$part->appendChild($n umber);
$part->appendChild($p rice);

$dom->appendChild($r esponse);

echo $dom->saveXML();

What output should I see on the browser? I only see bla9999. It does not show
the XML file with the tags?

Thanks
Gary

Jul 17 '05 #9
Gary Quiring wrote:
On Wed, 18 May 2005 15:14:36 +0200, Azeus <IF************ *************@M P.com> wrote:
Try the following Dom syntax:
And try to put some of your own stuff in it.

<... SNIP CODE ...> What output should I see on the browser? I only see bla9999. It

does not show the XML file with the tags?


Now view the source in the browser. There's your XML. If you want the
browser window to display the XML, you need to send the right
Content-Type MIME header (which is text/xml).

--
Oli

Jul 17 '05 #10

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

Similar topics

2
282
by: JVince | last post by:
how do you create context sensitive help on your app ? I wanted to create to the help file in MS word and compile it to a help file which would be used in my app. any ideas are highly appreciated. Thanks so much
4
2709
by: Richard Tierney | last post by:
To create help output (the response to "myprog --help", for example) I currently create a big .h file, which includes a single string, such as: static char *help_text = "\ myprog: my program\n\ loads and\n\ loads of\n\ painfully manually\n\ formatted and\n\
1
1331
by: Diego F. | last post by:
I'm trying to show my application help. I installed VSHIK 2003 to create a simple help file. Now I need to integrate it into my application. I have two problems: - I don't know how to register the help file. I created a setup project and included the HxS file, but it doesn't open. - I tried also with a .chm file and it works pressing F1, but I don't know how to show the help pressing a menuitem component.
0
263
by: PK | last post by:
Hello, I would like to know how we can create help files or online help for any application in .NET. Also could someone tell me briefly whats exactly Microsoft Help v.1.3 or v.2.0? Thanks in advance. PK
2
1253
by: Mike TI | last post by:
Mar 20, 2006 Hi All I am building an application in VB.Net 2005. I want to create a Help Doc as I go about. Can someone please guide me the easiest way to create a Help Doc for use in VB.Net 2005 application.
1
1213
by: jack | last post by:
Hi Im newbie in dotnet and wanted to create help file from dotnet is it possible to create a help file is there any tool to create help file thanks for replying me.
3
9532
by: haltonbj | last post by:
I'm new to access but I've almost finished a dbase and only need to split the data and finalise the security. I've even written a lousy word manual however how do I amalgamate/create the document as an individual help package within access I'm sure there are many Accesseloreates that have done this but I've no idea where to start
4
1546
by: Coleen | last post by:
Hi All :-) I'm not sure where to post this, but my organization is looking for a good software application that is not terribly expensive that allows you to create documentationand help files and is able to be integrated into a .Net application. Any suggestions? Any help, suggestions, links would be greatly appreciated. TIA, Coleen
7
12684
by: Supriya | last post by:
Hi All, Is there any way to create .chm file programmatically? Please let me know. Thanks in advance. Supriya
5
1438
pentahari
by: pentahari | last post by:
how to create help document for ex : Help.chm
0
9663
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...
1
10136
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
9979
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
9016
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...
1
7525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
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
2
3695
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.