我正在尝试将 xml 文件中的注释添加到特定元素,每个元素都有其唯一的名称。我的文件是一个翻译文件,所以它只包含字符串元素和复数等。
这是我第一次尝试添加评论时使用的片段:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="debug">You wish you could use that!</string>
<string name="author">foobar</string> <!-- Insert author name here -->
<string name="error">Wutfuq</string> <!-- New! -->
</resources>
在我的 php 文件中,我尝试向名为“debug”的元素添加注释:
<?php
error_reporting(E_ALL);
include "SimpleDOM.php";
$xml = simpledom_load_file("strings.xml");
$xml->xpath("//string[@name='debug']")->insertComment(' This is a test comment ', 'after');
$xml -> asXML('test.xml');
echo "This line should be shown, otherwise there might be some error";
?>
所以我的问题是这行不通。整个页面都是白色的,没有错误,也不会创建我的 test.xml,所以错误似乎出现在我在使用 xpath 时尝试添加注释的那一行。
我将不胜感激,请不要试图说服我使用 DOM。