php 解析 xml - 错误 : StartTag: invalid element name

标签 php mysql xml

我在从 php 中的 sql 查询中获取数据到 xml 时遇到了严重的问题。我总是收到错误消息:StartTag:元素名称无效。 Start-Element 是一个数字,我不知道这是否重要?!?

也许你们可以帮助我!!

PHP:

$query = "SELECT r.object_id,
t.term_taxonomy_id,
t.term_id,
t.taxonomy,
t.description,
p.post_date_gmt,
p.post_content,
p.post_title,
p.post_excerpt 
FROM wp_posts p,
wp_term_taxonomy t,
wp_term_relationships r
WHERE r.object_id= p.id
AND t.term_taxonomy_id = r.term_taxonomy_id
AND p.post_status = 'publish'
AND p.post_type = 'post'
AND to_days(p.post_date_gmt) >= to_days(now()) - 120
ORDER BY p.post_date DESC";


// DB Connect

$connection = mysql_connect($server, $user, $password);
mysql_select_db($dbName, $connection);
$res = mysql_query($query);

// XML Output

$xml = '<?xml version="1.0" encoding="UTF-8"?>
<standing version="1.0">';
while ($row = mysql_fetch_assoc($res)){
    $xml .= '
    <'.$row['object_id'].'>
      <term_taxonomy>'.$row['taxonomy'].'</term_taxonomy>
      <description>'.$row['description'].'</description>
      <post_date>'.$row['post_date_gmt'].'</post_date>
      <post_content>'.$row['post_content'].'</post_content>
      <post_title>'.$row['post_title'].'</pst_title>
      <post_exerpt>'.$row['post_exerpt'].'</post_exerpt>
    </'.$row['object_id'].'>
    ';
}
$xml.= '</standing>';


// Write to file

$file = 'News.xml'; 
if(is_file($file)) unlink($file);
$fp = fopen($file, "w+");
fwrite($fp, $xml);
fclose($fp);
mysql_close ($connection);
?>

最佳答案

是的。那很重要。 XML 应始终以下列之一开头:

[A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

(为了好品味,建议标签名称以描述性词或缩写开头)

如是说w3 .让它写下来。让它完成吧。

您应该能够替换(并使 ID 成为属性)

<object id="'.$row['object_id'].'">
/* step 2 */
</object>

关于php 解析 xml - 错误 : StartTag: invalid element name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588888/

相关文章:

php - 自offline_access弃用以来如何延长访问 token 的有效性

php - PHP 中的 Where IN 子句和 while 循环的输出 while 外部

java - 不同API级别上View元素的不同外观-Android

php - 使用 Doctrine2 从字符串中插入日期

php - 调用未定义函数 mysqli_begin_transaction() 错误

php - 如何使用正则表达式从字符串中提取所有整数值?

php - Laravel 5 - 数据库连接被拒绝

javascript - 使用 php 将 mysql 数据转换为 javascript 图表

xml - XSLT 对每个父节点的多个子节点进行排序

json - BizTalk JSON 反序列化