首页 \ 问答 \ 将PHP文件解析为XML文件?(Parse a PHP file as an XML file?)

将PHP文件解析为XML文件?(Parse a PHP file as an XML file?)

我一直在研究一个在XML文件中显示数据的项目。 (这有点像一个API)。 我知道如何用PHP解析XML,以及如何在PHP中创建XML文件,但它们不能一起工作。 :)

基本上,我有两个文件: parse.phpxml.php

xml.php从MySQL数据库xml.php信息,并将其输出为XML。

parse.php加载并解析xml.php并将其输出为HTML。

如果我运行parse.php ,它不会加载xml.php 。 但是,如果我复制输出的XML(来自xml.php )并将其保存为xml.xml文件(并将parse.php中的文件名parse.php为“xml.xml”),它将起作用。 我非常感谢任何帮助。

parse.php的内容:

<?php

    $doc = "xml.php";

    $doc = @simplexml_load_file($doc) or die("Server Error: Recipe not found!");

    $title = $doc->title;

    echo $title

?>

xml.php的内容:

<?php

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

    $dbc = mysql... //gets data from database

    echo "<!DOCTYPE..."; //xml stuff here

    echo "<title>" . $dataFromMySQL . "</title>";

?>

数据库连接起作用,并且XML中的DOCTYPE正常,所以这不是问题。

同样,当我使用PHP动态生成XML时,我只会遇到问题。 如果它是一个.XML文件,它可以正常工作。

谁能帮我?

谢谢。


I have been working on a project that displays data in an XML file. (It's kind of like an API). I know how to parse XML with PHP, and how to make an XML file in PHP, but they don't work together. :)

Basically, I have two files: parse.php and xml.php.

xml.php grabs info from a MySQL database, and outputs it as XML.

parse.php loads and parses xml.php and outputs it as HTML.

If I run parse.php, it does not load xml.php. However, if I copy the outputted XML (from xml.php) and save it as a xml.xml file (and change the filename in parse.php to 'xml.xml') it works. I'd really appreciate any help.

Content of parse.php:

<?php

    $doc = "xml.php";

    $doc = @simplexml_load_file($doc) or die("Server Error: Recipe not found!");

    $title = $doc->title;

    echo $title

?>

Content of xml.php:

<?php

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

    $dbc = mysql... //gets data from database

    echo "<!DOCTYPE..."; //xml stuff here

    echo "<title>" . $dataFromMySQL . "</title>";

?>

The database connection works, and the DOCTYPE in the XML is ok, so that's not the problem.

Again, I only get the problem when I generate XML dynamically using PHP. If it's a .XML file, it works fine.

Can anyone help me?

Thanks.


原文:https://stackoverflow.com/questions/10742985
更新时间:2022-08-14 13:08

最满意答案

你的程序没有内存泄漏,你有

==7658==    definitely lost: 0 bytes in 0 blocks
==7658==    indirectly lost: 0 bytes in 0 blocks
==7658==      possibly lost: 0 bytes in 0 blocks

“仍然可达”并不意味着内存泄漏。

这里有很多关于valgrind“仍然可以达到”的问题。 他们中有一些:


Your program don't have memory leaks, you have

==7658==    definitely lost: 0 bytes in 0 blocks
==7658==    indirectly lost: 0 bytes in 0 blocks
==7658==      possibly lost: 0 bytes in 0 blocks

"still reachable" does not mean memory leak.

There are much questions here about "still reachable" by valgrind. Some of them:

相关问答

更多
  • 你的程序没有内存泄漏,你有 ==7658== definitely lost: 0 bytes in 0 blocks ==7658== indirectly lost: 0 bytes in 0 blocks ==7658== possibly lost: 0 bytes in 0 blocks “仍然可达”并不意味着内存泄漏。 这里有很多关于valgrind“仍然可以达到”的问题。 他们中有一些: Valgrind检测到仍然可达泄漏 仍然可以通过valgrind访问 Valgri ...
  • 我不知道UIImagePNGRepresentation有任何“漏洞”,但它肯定是对内存的过度使用,但这里有几个问题: 首先,通过UIImage对原始资产进行往返,然后使用UIImagePNGRepresentation()过程相当低效,最终可能会得到比原始资产大得多的NSData 。 例如,我选择了一张原始资产为1.5mb的照片, UIImageJPEGRepresentation ( compressionQuality为1.0)为6mb, UIImagePNGRepresentation()为10mb ...
  • 一个长镜头的位,但我不确定它是否只是我的项目中的一个bug,但我曾在viewWillAppear设置tintColor时出现类似的问题。 我最终在再次分配颜色之前添加了一个nil检查,这为我解决了这个问题(我没有做任何进一步的调查,所以我可能是错的)。 if (nil == self.navigationController.navigationBar.tintColor) { self.navigationController.navigationBar = [UIColor colorWithRed ...
  • 从函数返回后,您将发布tempMapListings 。 在return语句之后,不再在该分支上执行代码。 因此,您的[tempListListings release]语句永远不会运行。 而且,当你返回它时,你实际上并不想立即释放它 - 调用者永远不会有机会保留阵列! 自动释放池是你的朋友。 添加到自动释放池的对象将“代表”“最终”释放,让您的调用者有时间获取结果。 要将对象添加到默认池,请将分配行更改为 NSMutableArray *tempMapListings = [[[NSMutableArra ...
  • reportError()应该在switchSystem声明为virtual,因为它在errorContainer 。 char*应该是std::string以避免所有不必要的工作。 是否有某些原因你不能使用std::vector而不是new[] ? 当指向静态文字字符串时,不应delete[] errorMessage 。 这导致未定义的行为。 (翻译:Bad Thing(TM)。) 为什么要迭代计算和复制char*的内容? 这是在乞求麻烦。 你没有做任何事来保护自己免受伤害。 ...
  • 如果您正在阅读6284293文档并在对象层次结构中持有这些文档,那么显然您的应用程序将使用相当数量的内存。 由于我们不知道这些物体的大小,很难说你的使用是否超出预期。 另外,请记住CLR代表您的应用程序分配和释放内存。 因此,即使您的应用程序已释放内存,也可能不会立即反映在进程的内存使用情况上。 如果应用程序没有泄漏,则会在某些时候回收此内存,但您不应期望在进程内存使用中立即反映托管内存使用情况,因为CLR可能会保留内存以减少分配/释放的数量。 If you're reading 6284293 docum ...
  • 您的第一次泄漏是因为您致电: [sortedDummyArray retain]; 你已经调用了一个这样做的alloc,但是你最后只释放了一次(所以删除上面一行)然后你也重新分配它是不正确的。 导致第二次泄漏是因为您已使用alloc设置finalArray,然后将其替换为函数的结果。 您可以通过替换此行来解决此问题: NSMutableArray *finalArray = [[NSMutableArray alloc]initWithArray:sortedDummyArray]; 有了这个: NSM ...
  • 是的,这很正常。 第一次调用CoCreateInstance会将CLR加载到您的进程中。 它创建了主要的AppDomain来加载托管代码,垃圾收集堆,加载器堆和一些内部数据结构。 在接口指针上调用Release()方法不会卸载CLR。 它坚持为将来加载和执行托管代码的任何请求提供服务。 在进程终止之前,主应用程序域不会被卸载。 非托管内存诊断工具不会知道这是正常的。 真正的内存泄漏是在没有上限的情况下增加进程的VM大小的内存泄漏。 通过运行此代码十亿次,说服自己这不是真正的内存泄漏。 Yes, this i ...
  • created活动时占用内存。 但是如果你在活动被destroyed时设法释放它们,几乎内存泄漏问题就会解决。 在onDestroy()方法中编写以下代码。 relativeLayout.setBackroundResource(null); 这将删除相对布局的背景。 编辑 relativeLayout.setBackground(0); 将背景设置为给定资源。 资源应引用Drawable对象或0以删除背景。 参考: setBackgroundResource Memory is occupied wh ...
  • 我没有检查你的完整代码,但内存泄漏可能是强委托引用的可能输出。 您会看到,当您将委托附加到对象事件时,除非手动删除委托引用,否则永远不会对该对象进行垃圾回收。 以下是msdn的文档参考,以帮助您更好地理解场景并提供可能的解决方案 - http://msdn.microsoft.com/en-us/library/aa970850(v=vs.110).aspx 侦听事件可能会导致内存泄漏。 侦听事件的典型技术是使用特定于语言的语法将处理程序附加到源上的事件。 例如,在C#中,该语法为:source.SomeE ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)