尝试从 SVN 日志命令解析 XML 时出错

发布于 2024-10-02 17:45:45 字数 898 浏览 0 评论 0原文

我正在尝试构建一个简单的下拉列表,它将显示特定文件的修订版本。从选择的选项中,我使用 jQuery 获取该修订版中包含的当前文本并填充文本区域(使用 svn cat)。

我的 HTML 文件中的标头:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

我的 shell 命令:

svn log --xml "file:///C:/Documents and Settings/username_here/Desktop/svnrepo/Web/trunk/my_file.php"

XML 解析调用:

$xmlData = simplexml_load_string(utf8_decode(trim(shell_exec($cmd))));

此时,我收到此错误:

输入的不是正确的UTF-8,指示 编码!字节:0xE9 0x20 0xE7 0x61

-我正在使用 utf8_decode 函数来帮助正确显示字符。例如,“é”显示为“é” -

如果我将元标记更改为 utf-8,它会正确显示。但是,我需要为每个组织设定规则 ISO-8859-1

-我使用 file:/// 协议调用我的 SVN 存储库作为暂时的临时措施

有趣的是,我的 jQuery 调用只需要一个标头调用它可以正确显示字符(shell_exec(svn cat...)):

header('Content-type: text/html; charset=ISO-8859-1') ;

I'm trying to build a simple drop down that will display the revisions of a specific file. From the option chosen, I use jQuery to fetch the current text contained in that revision and populate a textarea (using svn cat).

The header in my HTML file:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

My shell command:

svn log --xml "file:///C:/Documents and Settings/username_here/Desktop/svnrepo/Web/trunk/my_file.php"

XML parsing call:

$xmlData = simplexml_load_string(utf8_decode(trim(shell_exec($cmd))));

At this point, I get this error:

Input is not proper UTF-8, indicate
encoding ! Bytes: 0xE9 0x20 0xE7 0x61

-I'm using the utf8_decode function to help display characters properly. For instance, "é" gets displayed as "é"

-If I change the meta tag to utf-8, it displays properly. However, I need to have ISO-8859-1 per organizational set rules

-I'm calling my SVN repo using the file:/// protocol as a temporary measure for the moment

Funny enough, my jQuery call only necessitated a header call for it to display the characters properly (shell_exec(svn cat...)):

header('Content-type: text/html; charset=ISO-8859-1') ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杯别 2024-10-09 17:45:45

根据评论,我在读取 XML 时删除了 utf8_decode 函数,并在显示文本时应用它。

echo '<select id="selID">';
foreach ($xmlData->logentry as $entry){
 echo utf8_decode('<option value="'.$entry['revision'].'">rev '.$entry['revision'].' by '.$entry->author.' @ '.substr($entry->date,0,19).' '.$entry->msg.'</option>');
}
echo '</select><input type="button" id="svn_select" value="Load revision" />';

现在就像一个魅力。

Per the comments, I removed the utf8_decode function when reading in the XML and applied it when displaying the text.

echo '<select id="selID">';
foreach ($xmlData->logentry as $entry){
 echo utf8_decode('<option value="'.$entry['revision'].'">rev '.$entry['revision'].' by '.$entry->author.' @ '.substr($entry->date,0,19).' '.$entry->msg.'</option>');
}
echo '</select><input type="button" id="svn_select" value="Load revision" />';

Works like a charm now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文