使用PHP 5帮助创建XML [英] XML create with PHP 5 help

查看:51
本文介绍了使用PHP 5帮助创建XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP5创建XML字符串。我所遵循的例子似乎是使用过时的libary调用
。我尝试了new_xmldoc()和新的DomDocument。

两者都得到了未定义的错误。如何创建一个XML字符串,它看起来像这样:


< 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>


谢谢

加里Quiring

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

推荐答案

你只需将它回显给浏览器,然后发送XML内容

标题。


(或保存到变量中,存储到文件中)


例如:


<?php

标题(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>在消息中写道

news:5e ******************************** @ 4ax.com ...
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...
我需要使用PHP5创建一个XML字符串。我所遵循的例子似乎是在使用过时的libary调用。我尝试了new_xmldoc()和新的
DomDocument。
两者都有未定义的错误。如何创建一个XML字符串,它将看起来像这样:

< 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>

谢谢
Gary Quiring
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



2005年5月17日星期二14:24:19 +0100,Alistair Baillie SS2002

< ab ****** @ cis.strath.ac.uk>写道:
On Tue, 17 May 2005 14:24:19 +0100, "Alistair Baillie SS2002"
<ab******@cis.strath.ac.uk> wrote:
你只需将它回显给浏览器,然后发送XML内容

(或将其保存到一个变量,用于存储到文件中)

例如:

<?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>" ;;
?>
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.


假设XML输出大致相同,只是用于

循环,添加不同的长度。


如果你的意思是完全不同你可以使用3Dimensional数组,

然后从那里生成XML字符串。


除了这两种方法之外,我恐怕无法帮助你。对不起。


创建RSS输出的示例(不使用3d数组):

<?php

/ *** *

* Blog Off.net

*

* @author:Alistair Baillie

* @website:< a rel =nofollowhref =http://www.alistairbaillie.co.uktarget =_ blank> http://www.alistairbaillie.co.uk

* @version:1.0

* @sourcepath:\\BO\

*

*此文件的内容及任何相关内容文件,包括但没有

方式

*仅限于艺术品和图像,版权所有(c)2005 Alistair D Baillie

*任何未经授权的严格禁止复制或发行!

**** /

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!
****/


这篇关于使用PHP 5帮助创建XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆