任何人都可以指导我如何使用这个escape_value()。
我想转义这些字符:
因为它引用了无效的字符数错误。
这是我的代码
my $xs = XML::Simple->new( KeepRoot => 1, KeyAttr => 1, ForceArray => 1 );
$xs->XMLout($filename, escape_value(`'`')); // but this is not working
my $data = $xs->XMLin($filename);
提前致谢
答案 0 :(得分:1)
查看code,似乎escape_value
方法接受一个字符串并返回该字符串,并返回以下内容:
>
至>
<
至<
&
至&
"
至"
它甚至不操纵对象的结构。如果你直接调用它,你只需这样做:
my $string = '"Remove quotes" & <entities> quotes';
my $encoded_string = $self->escape_value( "$string" );
say $encoded_string; #"Remove quotes" & and <entities> quotes
哎呀,为什么还要为面向对象而烦恼?
my $string = '"Remove quotes" & <entities> quotes';
my $encoded_string = XML::Simple::escape_value( "$string" );
say $encoded_string; #"Remove quotes" & and <entities> quote
如果选项XMLOut
未设置或设置为NoEscape
,则0
本身会调用此子例程。
在代码的第636行中,XMLOut
方法正在调用value_to_xml
方法。这将数据结构传递到XMLOut并创建XML文本。然后,value_to_xml
方法会在第1431行调用escape_string
方法。
答案 1 :(得分:1)
XML中不允许使用U + 000C。
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
甚至没有逃脱。
使用字符引用引用的字符必须与
Char
的制作匹配。