<<<操作符需PHP5.3以上版本才能支持,下面程序在wamp环境下测试完成。

<?php

// Set the content type to be XML, so that the browser will recognise it as XML.

header( "content-type: application/xml; charset=GBK" );  显示$xml对象时此语句要注释掉
$string = <<<XML
<?xml version='1.0' encoding='GBK'?>       此行要顶格写
  <root>
    <title>Forty What?</title>
    <from>Joe</from>
    <to>Jane</to>
    <body>I know that's the answer -- but what's the question?</body>
  </root>
XML;

echo $string;              --显示输出受header语句有影响。
//var_dump($string);

$xml = simplexml_load_string($string);
//var_dump($xml);      --如header语句保留,对象结果无法显示
?>

结果输出(echo 显示)

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<root>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
</root>
var_dump($string)结果显示

string

 '<?xml version='1.0' encoding='GBK'?>
<root>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body> I know that's the answer -- but what's the question? </body>
</root> ' (length=243)

Joe Jane I know that's the answer -- but what's the question?

var_dump($xml) 结果显示

object(SimpleXMLElement)[1]
public 'title' =>

string

 'Forty What?' (length=11)
public 'from' =>

string

 'Joe' (length=3)
public 'to' =>

string

 'Jane' (length=4)
public 'body' =>

string

 '    I know that's the answer -- but what's the question?  ' (length=58)

PHP 操作XML文档的更多相关文章

  1. 操作xml文档的常用方式

    1.操作XML文档的两种常用方式: 1)使用XmlReader类和XmlWriter类操作 XmlReader是基于数据流的,占用极少的内存,是只读方式的,所以速度极快.只能采用遍历的模式查找数据节点 ...

  2. 操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP)

    原文:操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP) 不管是用 PHP 还是 C#, 在操作 XML 的时候我们除了一个节点一个节点去取值之外, 还有一个非常方便的表达式, 就是 ...

  3. 用ORM的思想操作XML文档,一个对象就搞定不要太简单。滚蛋吧!XmlDocument、XmlNode、Xml***……

    大家有没有这样的感受,一涉及XML文档操作就得百度一遍.是不是非!常!烦!.各种类型,各种方法,更别提为了找到一个节点多费劲.本来想写个XML操作的工具方法,写了两行一想既然XML文档是有规律的,如果 ...

  4. C#操作XML文档---基础

    增查改删代码如下 public void CreateXML() { XmlDocument xml = new XmlDocument(); xml.AppendChild(xml.CreateXm ...

  5. C#XmlHelper操作Xml文档的帮助类

    using System.Xml; using System.Data; namespace DotNet.Utilities { /// <summary> /// Xml的操作公共类 ...

  6. [XML] C# XmlHelper操作Xml文档的帮助类 (转载)

    点击下载 XmlHelper.rar 主要功能如下所示 /// <summary> /// 类说明:XmlHelper /// 编 码 人:苏飞 /// 联系方式:361983679 // ...

  7. 文档对象模型操作xml文档

    简介 :文档对象模型(DOM)是一种用于处理xml文档的API函数集. 2.1文档对象模型概述 按照W3C的定义,DOM是“一种允许程序或脚本动态地访问更新文档内容,结构和样式的.独立于平台和语言的规 ...

  8. C#操作XML文档(XmlDocument、XmlNode、XmlAttribute、SelectSingleNode、SelectNodes、XmlNodeList)

    XML文档是一种通用的文档,这种文档既可以用.config作为后缀也可以用.xml作为后缀.XML文档主要由元素节点和节点的属性共同构成的.它有且仅有一个根节点,其他的节点全部都是根节点的子节点或者子 ...

  9. dom4j操作xml文档

    java Dom4j解析XML文件 标签(空格分隔):java进阶 xml文档: <?xml version="1.0" encoding="UTF-8" ...

  10. C# 操作XML文档 使用XmlDocument类方法

    W3C制定了XML DOM标准.很多编程语言中多提供了支持W3C XML DOM标准的API.我在之前的文章中介绍过如何使用Javascript对XML文档进行加载与查询.在本文中,我来介绍一下.Ne ...

随机推荐

  1. Python 之 matplotlib (十六)Animation动画【转】

    本文转载自:https://blog.csdn.net/wangsiji_buaa/article/details/80057875 代码:   import matplotlib.pyplot as ...

  2. JSON和GSON的使用

    JSONObject 处理问题 相关博客参考:https://www.cnblogs.com/free-dom/p/5801866.html json-lib 和google gson 的使用 Tor ...

  3. java sleep()和wait()的区别

    java sleep()和wait()的区别? sleep()和wait()都能阻塞当前线程. 区别1: sleep()属于Thread类:wait()属于Object类. 区别2: 调用sleep( ...

  4. $1...$9 属性 (RegExp) (JavaScript)

    返回在模式匹配期间找到的,所存储的最近的九个部分. 只读.     RegExp.$n 参数     RegExp 始终为全局 RegExp 对象. n 1 至 9 之间的任意整数. 备注     每 ...

  5. pOJ-1061 exgcd求同余方程组

    链接 就是求(m-n)*a+b*l=y-x, 类似于求解a*x+b*y=c,r=gcd(a,b),当c%r==0时有解,用exgcd求出a*x+b*y=gcd(a,b)的解,然后x*c/gcd(a,b ...

  6. poj3517约瑟夫问题

    直接套公式+ 假设除去第k个人. 0, 1, 2, 3, ..., k-2, k-1, k, ..., n-1 //original sequence (1) 0, 1, 2, 3, ..., k-2 ...

  7. [csharp] bool IsNumeric(Type type)

    /* "C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe" /out:IsNumericType.exe IsNumericType. ...

  8. vue 时间格式化

    export function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.g ...

  9. ionic2常见问题——启动后白屏问题

    问题描述 app启动后大概有几秒白屏,才会显示首页. 解决方案 图 1-最初config.xml配置 图 2-更改后的splash配置 代码: <preference name="Sh ...

  10. LeetCode OJ:Roman to Integer(转换罗马字符到整数)

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...