473,837 Members | 1,769 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 6679
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
2711
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
1335
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
1258
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
1216
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
9538
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
1547
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
12685
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
1439
pentahari
by: pentahari | last post by:
how to create help document for ex : Help.chm
0
9691
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
10891
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10582
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...
0
10280
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
9418
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
7821
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
5677
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...
1
4480
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
4054
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.