SimpleXMLElement 文件不加载 xmlString [英] SimpleXMLElement file does not load xmlString

查看:32
本文介绍了SimpleXMLElement 文件不加载 xmlString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决基于 XML 的问题.到目前为止,由于某种原因,它被证明是一个无赖.我的代码只有两行,出于某种原因没有加载任何内容.

I am trying to work on an XML Based problem. So far, it's proving to be a bummer for some reason. My code is only two lines and for some reason nothing is loading in.

代码:

$xmlString = file_get_contents('file.xml');
$xmlObject = simplexml_load_string($xmlString); 
// also in the above line I have tried
// 1. new SimpleXMLElement('file.xml') 
// 2. simplexml_load_file('file.xml')

函数没有加载,我可以通过 var_dumping $xmlObject 判断,它返回布尔假.

The functions do not load, and this I can tell by var_dumping $xmlObject, which returns boolean false.

file_get_contents 确实加载字符串 $xmlString 并且 var_dumping 它返回字符串,因此文件路径的位置在这里不是问题.

file_get_contents does load the string $xmlString and var_dumping it returns the string, so location of the file path is not an issue here.

有人知道这里发生了什么吗?

Anybody know what's happening here?

谢谢

推荐答案

您的 XML 可能无效.查看描述如何处理这些错误的精美 PHP 手册:

Your XML is probably invalid. Look at the fine PHP manual that describes how to handle those errors:

http://php.net/manual/en/simplexml.examples-错误.php

您还可以使用 xmllint 等命令行工具验证您的 XML:

You can also validate your XML with command line tools like xmllint:

$ xmllint --noout /path/to/file.xml
file.xml:1: parser error : XML declaration allowed only at the start of the document

这篇关于SimpleXMLElement 文件不加载 xmlString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆