开发者

creation of xml document [closed]

开发者 https://www.devze.com 2023-02-14 02:16 出处:网络
It's difficult to tell what is being asked here. This qu开发者_开发问答estion is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This qu开发者_开发问答estion is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

I have a table in my database (Mysql) which has 6 columns. I am using PHP forms to store the data in this database. One of the column is for url. I am able to store the data in the database and now I want to construct an XML document with the URL as the data.

Database name: probe_config
table name   : webmeasurementsuite

My database details are as follows:

url:(varchar,binary and the default value is null)
replication:(integer,unsigned,zerofill and default value is null)
wait:(integer,unsigned,zerofill and default value is null)
timeout:(integer,unsigned,zerofill and default value is null)
clearcache:(varchar,binary and default value is null)
name:(varchar,binary and default value is null)
id  :(integer,notnull,autoinc,unsigned,zerofill and default value is null)

Can anyone help me in converting this to xml document?


Once you get your database results as an array, you can use a function like this to convert that array into an XML document. But do not assume such a function is best performance-wise or software design wise.

Assuming that your database connection is already done,

$sth = $dbh->prepare("SELECT url FROM webmeasurementsuite");
$sth->execute();
$result = $sth->fetchAll();

$xml = '<?xml version="1.0" encoding="UTF-8"?>';

foreach ($result as $v) {
    $xml .= '<url>'.htmlspecialchars($v['url'], ENT_COMPAT, 'UTF-8').'</url>';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消