473,467 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Create 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 6651
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.com> wrote in message
news:5e********************************@4ax.com...
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.strath.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("Content-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("includes/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>The 5 latest postings to Blog Off.net Journals</description>
<language>en-gb</language>

<?php
$query = $db->query("SELECT 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_displayname 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><?php echo stripslashes( $theData['users_displayname'] );
?></dc:creator>
<dc:date><?php echo date("Y-m-d", $theData['blogs_datetime']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}

if ( $_REQUEST['id'] > 0 ) {
$id = addslashes($_REQUEST['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>The 5 latest postings to this persons blog!</description>
<language>en-gb</language>

<?php
$query = $db->query("SELECT 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_displayname 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><?php echo stripslashes( $theData['users_displayname'] );
?></dc:creator>
<dc:date><?php 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.strath.ac.uk> wrote in message
news:42********@nntphost.cis.strath.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("includes/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>The 5 latest postings to Blog Off.net Journals</description>
<language>en-gb</language>

<?php
$query = $db->query("SELECT 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_displayname 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><?php echo stripslashes( $theData['users_displayname'] );
?></dc:creator>
<dc:date><?php echo date("Y-m-d", $theData['blogs_datetime']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}

if ( $_REQUEST['id'] > 0 ) {
$id = addslashes($_REQUEST['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>The 5 latest postings to this persons blog!</description>
<language>en-gb</language>

<?php
$query = $db->query("SELECT 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_displayname 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><?php echo stripslashes( $theData['users_displayname'] );
?></dc:creator>
<dc:date><?php 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($data);
$data->appendChild($parts);
$parts->appendChild($part);
$part->appendChild($number);
$part->appendChild($price);

$dom->appendChild($response);

echo $dom->saveXML();
Jul 17 '05 #8
On Wed, 18 May 2005 15:14:36 +0200, Azeus <IF*************************@MP.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($data);
$data->appendChild($parts);
$parts->appendChild($part);
$part->appendChild($number);
$part->appendChild($price);

$dom->appendChild($response);

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*************************@MP.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
On 18 May 2005 12:30:58 -0700, "Oli Filth" <ca***@olifilth.co.uk> wrote:
Gary Quiring wrote:
On Wed, 18 May 2005 15:14:36 +0200, Azeus

<IF*************************@MP.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).

If I view the source I still see bla9999
Jul 17 '05 #11
On 18 May 2005 12:30:58 -0700, "Oli Filth" <ca***@olifilth.co.uk> wrote:
Gary Quiring wrote:
On Wed, 18 May 2005 15:14:36 +0200, Azeus

<IF*************************@MP.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).

Ok I wrote the object to a file and I see the tags. I don't know why my browser
is not showing them when viewing the source.

Thanks
Gary
Jul 17 '05 #12
did you send the txt/xml header?

Jul 17 '05 #13
Gary Quiring <gq******@msn.com> wrote:

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.


You have to judge it for yourself, of course, but it is often just as easy
and is ALWAYS more efficient to create XML without the help of an XML
library.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #14

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

Similar topics

2
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...
4
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\...
1
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...
0
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...
2
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...
1
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
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...
4
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...
7
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
pentahari
by: pentahari | last post by:
how to create help document for ex : Help.chm
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...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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...
0
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...

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.