【问题标题】:Loading xml from php/mysql for sencha architect为 sencha 架构师从 php/mysql 加载 xml
【发布时间】:2012-10-19 07:15:22
【问题描述】:

喂?我正在尝试使用 mysql 数据库中的数据在 sencha 架构师中加载 xml 存储。 我正在构建我的 xml,如下所示;

//AFTER MYSQL QUERY

    $dom = new DOMDocument("1.0");
    $dom->formatOutput = true;

// display document in browser as plain text
 // for readability purposes
    header("Content-Type: text/plain");

// create root element
$root = $dom->createElement("stores");
$dom->appendChild($root);

while ($row = mysql_fetch_array($result)) {

//create child element
$storeitem = $dom->createElement("store");
$root->appendChild($storeitem);

// Company label
$company = $dom->createAttribute("c");
$storeitem->appendChild($company);

// company value
$companyValue = $dom->createTextNode($row['company']);
$company->appendChild($companyValue);

}
// save and display tree
echo $dom->saveXML();


//OUTPUT
<stores>
<store c="company1"/>
<store c="company2"/>
</stores>

输出是结构化的 xml。当我将此 xml 复制并粘贴到 xml 文档中时,例如 test.xml 并使用它,它工作得很好。但是,尝试使用来自 php 的回显 xml 文件不起作用。希望我说清楚了。请帮忙。

【问题讨论】:

  • 您必须为文件设置 XML 标头。

标签: php mysql xml ajax extjs


【解决方案1】:

试试这样:

 header ("content-type: text/xml");

不要使用纯标题

header ("content-type: text/plain");

【讨论】:

    【解决方案2】:

    -> 设置内容类型为“XML” : header("Content-type: text/xml");

    -> 如果你的 php 程序要返回一个 xml 。检查您的 php 标签之前或之后是否存在任何空格。

    (check wheather you have left spaces or something else here, if so remove it all)
    <?php 
    ......
    ....
    ....
    ?>
    (check wheather you have left spaces or something else here, if so remove it all)
    

    问候,TechNew.In

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多