Reputation: 799
I'm having difficulty writing to a strings.xml file that contains an XLIFF element using LibXML. Note that I'm trying to write a value that already exists (had no problem parsing the node while reading). I also need to use appendWellBalancedChunk as I write HTML elements sometimes.
#!/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();
When I run this, I get the following:
$ perl xliff.pl
namespace error : Namespace prefix xliff on g is not defined
<xliff:g id="MILLISECONDS">%s</xliff:g>ms
^
Thanks
Upvotes: 0
Views: 242
Reputation: 17238
Adding a namespace declaration to the xml element will make your code run without errors:
my $string = '<xliff:g xmlns:xliff="urn:whatever" id="MILLISECONDS">%s</xliff:g>ms';
Upvotes: 1
Reputation: 4709
You are getting this error because you don't have an XML namespace defined for <xliff:g id="MILLISECONDS">%s</xliff:g>ms
Upvotes: 0