我在使用strings.xml编写包含XLIFF元素的LibXML文件时遇到了困难。请注意,我正在尝试编写一个已经存在的值(在读取时解析节点没有问题)。有时在编写appendWellBalancedChunk元素时,我也需要使用HTML。
#!/usr/bin/env perl
#
# Create a simple XML document
#
use strict;
use warnings;
use XML::LibXML;
my $doc = XML::LibXML::Document->new('1.0', 'utf-8');
my $root = $doc->createElement("resources");
$root->setAttribute('xmlns:xliff' => 'urn:oasis:names:tc:xliff:document:1.2');
my $tag = $doc->createElement("string");
$tag->setAttribute('name'=>'no_messages');
my $string = '<xliff:g id="MILLISECONDS">%s</xliff:g>ms';
$tag->appendWellBalancedChunk($string);
$root->appendChild($tag);
$doc->setDocumentElement($root);
print $doc->toString();当我运行这个程序时,我得到以下信息:
$ perl xliff.pl
namespace error : Namespace prefix xliff on g is not defined
<xliff:g id="MILLISECONDS">%s</xliff:g>ms
^谢谢
发布于 2015-02-13 10:57:24
将命名空间声明添加到xml元素将使代码运行时不会出现错误:
my $string = '<xliff:g xmlns:xliff="urn:whatever" id="MILLISECONDS">%s</xliff:g>ms';发布于 2015-02-13 05:55:18
因为您没有为<xliff:g id="MILLISECONDS">%s</xliff:g>ms定义XML命名空间,所以您得到了这个错误
https://stackoverflow.com/questions/28493308
复制相似问题