本人是小白,有错误的地方请指正,勿喷!

在写一个调查问卷的过程中用到了xml文件,如想要了解,可以通过以下链接简单学习:http://www.w3school.com.cn/xml/

所用工具:phpstudy+notepad++(使用utf-8编码无BOM)


出现的问题如下:最开始的代码如下:我想要 求出去长沙游玩的人数是多少人,

<?php
header('Content-Type: text/xml');
$xmlstr="<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
$xml = simplexml_load_string($xmlstr);
$count0 = $xml->movie[0]->count;
echo $count0;
?>


火狐浏览器上:

XML 解析错误:语法错误
位置:http://localhost:8080/diaocha/2.php
行 1,列 1:350

360浏览器上的错误:

This page contains the following errors:

error on line 1 at column 1: Document is empty

Below is a rendering of the page up to the first error.


需要改正的地方是:

去掉第一句:header('Content-Type: text/xml');即可。得到350


2、如果你是需要查看xml格式的时候

代码如下:

<?php
header('Content-Type: text/xml');
$xmlstr="<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";

就可以得出结果:

This XML file does not appear to have any style information associated with it. The document tree is shown below.


<movies>
<movie>
<title>旅游的人数</title>
<id>1</id>
<count>350</count>
<content>长沙</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>2</id>
<count>47</count>
<content>张家界</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>旅游的人数</title>
<id>4</id>
<count>80</count>
<content>南京</content>
</movie>
</movies>
";
 
上方的那句话可以不用管:在IE浏览器上没有那句话 所以只是因为其他浏览器的兼容性而已。

最新文章

  1. java多线程同步,等待,唤醒
  2. poj3740
  3. 实验七 状态机设计ADC0809采样控制电路
  4. ZOJ-3946 Highway Project (最短路)
  5. eclipse 恢复被删除的文件
  6. mybatis和hibernate区别和应用场景
  7. Java SE学习之printf 日期转换符
  8. 检查DISPLAY设置时Xlib出现No protocol specified错误
  9. bzoj:3616: War
  10. Spring Boot系列(一) Spring Boot准备知识
  11. Unity UGUI实现鼠标拖动图片
  12. 权限管理系统之项目框架搭建并集成日志、mybatis和分页
  13. MySQL建表 TIMESTAMP 类型字段问题
  14. CentOS7安装Jenkins自动化部署maven项目
  15. html 网页生产pdf文件
  16. MFC文档应用程序CToolBar:设置两个工具条并列停靠到同一条边上 转
  17. Solidity safesub防止溢出
  18. Scala具体解释---------控制结构和函数
  19. js打印相关,注意此方法受到IE安全性设置影响
  20. 台州学院maximum cow训练记录

热门文章

  1. [Linux] 检查是否已有进程在运行
  2. [Inno Setup] Do not show application version in “Program and Features” control panel
  3. hdu_2391 Filthy Rich DP
  4. vue2.x学习笔记(二十五)
  5. 解决Vue-cli3.0下scss文件编译过慢、卡顿问题
  6. MySQL重新初始化安装数据库
  7. Blockchain
  8. 基于TCP的客户端和服务器端的代码设计
  9. bzoj4173 数学
  10. linux 服务器/客户端 tcp通信的简单例子