PHP如何使用“;(PHP How to use quot; entities in XML with DOMdocument)
我正在修改由其他库生成的XML文件的内容。 我正在使用PHP(5.3.10)进行一些DOM修改并重新插入替换节点。
我正在使用的XML数据有
"
在我进行操作之前的元素,并且当我完成修改时,我想按照http://www.w3.org/TR/REC-xml/保留这些元素。但是我遇到了PHP改变
"
问题"
元素。 看看我的例子。$temp = 'Hello "XML".'; $doc = new DOMDocument('1.0', 'utf-8'); $newelement = $doc->createElement('description', $temp); $doc->appendChild($newelement); echo $doc->saveXML() . PHP_EOL; // shows " instead of element $node = $doc->getElementsByTagName('description')->item(0); echo $node->nodeValue . PHP_EOL; // also shows "
产量
<?xml version="1.0" encoding="utf-8"?> <description>Hello "XML".</description> Hello "XML".
这是PHP错误还是我做错了什么? 我希望没有必要在每个char位置使用createEntityReference。
类似问题: PHP XML实体编码问题
编辑:作为一个示例,显示saveXML不应该转换为
"
实体就像&
行为正常。 这个$ temp字符串应该输出,因为它最初是在saveXML()期间与实体一起输入的。$temp = 'Hello "XML" &.'; $doc = new DOMDocument('1.0', 'utf-8'); $newelement = $doc->createElement('description', $temp); $doc->appendChild($newelement); echo $doc->saveXML() . PHP_EOL; // shows " instead of element like & $node = $doc->getElementsByTagName('description')->item(0); echo $node->nodeValue . PHP_EOL; // also shows " &
产量
<?xml version="1.0" encoding="utf-8"?> <description>Hello "XML" &.</description> Hello "XML" &.
I am working on modifying the contents of an XML file generated by some other library. I'm making some DOM modifications with PHP (5.3.10) and reinserting a replacement node.
The XML data I'm working with has
"
; elements before I do the manipulation and I want to keep those elements as per http://www.w3.org/TR/REC-xml/ when I'm done with the modifications.However I'm having problems with PHP changing the
"
elements. See my example.$temp = 'Hello "XML".'; $doc = new DOMDocument('1.0', 'utf-8'); $newelement = $doc->createElement('description', $temp); $doc->appendChild($newelement); echo $doc->saveXML() . PHP_EOL; // shows " instead of element $node = $doc->getElementsByTagName('description')->item(0); echo $node->nodeValue . PHP_EOL; // also shows "
Output
<?xml version="1.0" encoding="utf-8"?> <description>Hello "XML".</description> Hello "XML".
Is this a PHP error or am I doing something wrong? I hope it isn't necessary to use createEntityReference in every char location.
Similar Question: PHP XML Entity Encoding issue
EDIT: As an example to show saveXML should not be converting the
"
entities just like the&
which behaves properly. This $temp string should really be output as it is initially entered with the entities during saveXML().$temp = 'Hello "XML" &.'; $doc = new DOMDocument('1.0', 'utf-8'); $newelement = $doc->createElement('description', $temp); $doc->appendChild($newelement); echo $doc->saveXML() . PHP_EOL; // shows " instead of element like & $node = $doc->getElementsByTagName('description')->item(0); echo $node->nodeValue . PHP_EOL; // also shows " &
Output
<?xml version="1.0" encoding="utf-8"?> <description>Hello "XML" &.</description> Hello "XML" &.
原文:https://stackoverflow.com/questions/28399653
最满意答案
你也需要这样做,你也需要更新网页,因为如果你看到在aspx页面上发布网页时,在标签标签上,cs文件的引用会自动升级。 因此,每当您发布时,将会生成一些随机的giud,并将附加到文件名,基本上它引用了名称空间。
因此,您还需要更新网页。
You need to do it as well, you need to update web pages as well, because if you will see when you publish the webpages in aspx page, on header tag, the reference of cs file upgrades itself. So whenever you will publish there will be some random giud generated and will appended to file name, basically it reference to the name space.
So you will need to update web pages as well.
相关问答
更多-
为什么不创建另一个项目,一个类库,并把它放在那里。 这是将这些课程与您网站其他部分分开的最佳方式。 为了回答您关于App_Code文件夹的具体问题,它可以在WebSite项目中作为Asp.Net文件夹进行选择。 但是从Web应用程序项目中,您可以创建一个新的文件夹并将其命名为App_Code,它将正常工作。 这是Visual Studio 2010 RC。 Why not create another project, a class library, and put it in there. That's ...
-
app_code文件夹(app_code folder)[2023-03-08]
你也需要这样做,你也需要更新网页,因为如果你看到在aspx页面上发布网页时,在标签标签上,cs文件的引用会自动升级。 因此,每当您发布时,将会生成一些随机的giud,并将附加到文件名,基本上它引用了名称空间。 因此,您还需要更新网页。 You need to do it as well, you need to update web pages as well, because if you will see when you publish the webpages in aspx page, on he ... -
DefaultProvider应该与提供程序中添加的名称匹配,如下所示:
The DefaultProvider should match the name added in providers, like this: ... -
是的,创建一个类库并将您需要的任何类型移动到该库中。 可以根据需要在多个位置引用此库。 Yes, create a class library and move any types you need into that library. This library can be referenced in as many places as you would like.
-
我相信App_Code或/ bin /的更新总是回收你的应用程序池。 如果您说有一个部署方案,其中.aspx.cs文件更新不会回收您的应用程序池,并且如果您能够引用页面类型本身,也许您可以将代码移动到.aspx中。 cs文件,以防止回收发生。 这可能是一个丑陋的选择。 一个建议是修改您的设计,以减少每天所需的源代码更新次数。 也许使用XML或数据库存储,并将您的应用程序设计得更通用,并且不太容易进行二进制更新。 或者将应用程序划分为几个较小的虚拟应用程序。 这样做的工作量可能更高,但在这种情况下,如果您的应 ...
-
VIsual Studio 2010中的ASP.NET项目中的App_Code文件夹(App_Code folder in ASP.NET project in VIsual Studio 2010)[2023-07-14]
请记住,该Web Site Project可以包含App_Code文件夹和Web Application Project不能! 因为所有项目都是为了代码。 Remember, that Web Site Project can contain App_Code folder and Web Application Project can't! Because all project is for code. -
您确定它是网站项目而不是Web应用程序吗? Are you sure it is web site project and not web application?
-
得到它了。 当您转到发布屏幕时,请转到设置 - >文件发布选项 - >发布期间的预编译。 不要像我那样做,颠覆你的办公桌,并威胁要愤怒地摧毁你的同事。 Got it. When you go to the publish screen, go to Settings -> File Publish Options -> precompile during publishing. Don't do like I did and overturn your desk and threaten to hulk s ...
-
Only the class files inside App_Code folder is able to refer in a file in ASP .NET website application. Why its so? 答案很简单网站应用程序按设计工作。 App_Code文件夹是一个特殊的ASP.NET RUNTIME文件夹。当您的站点实际在服务器上运行时,此文件夹中的任何文件都由ASP.NET编译。 This essentially allows you to drop random cl ...
-
绝对没有限制。 子目录只是文件系统分组,您必须手动将名称空间分配给App_Code中的所有类。 Absolutely No Restrictions. Sub-Directories are just FileSystem Grouping, you will have to assign the namespaces manually to all your classes in App_Code.