I wonder how to add namespace into my xml-attribute declaration: "xsi:nil='true'" I have to create a xml like this:
But I can't find the right way to do this. My Code:<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <node1 xsi:nil="true" /> </root>
Gives me this:1 #!/bin/perl 2 use strict; 3 use warnings; 4 use utf8; 5 6 use XML::Writer; 7 8 9 my $ns1 = "http://www.w3.org/2001/XMLSchema-instance"; 10 my $prefixMap = {$ns1 => "xsi"}; 11 12 my $writer = new XML::Writer( 13 OUTPUT => 'self', 14 DATA_INDENT => 3, 15 DATA_MODE => 1, 16 NAMESPACES => 1, 17 PREFIX_MAP => $prefixMap 18 ); 19 20 $writer->startTag("root"); 21 22 $writer->emptyTag("node1", ('nil' => "true")); 23 $writer->emptyTag("node3", [$ns1, "nil" => "true"]); 24 $writer->endTag("root"); 25 26 print $writer->to_string;
<root> <node1 nil="true" /> <node3 xsi:nil="xmlns:xsi" http://www.w3.org/2001/XMLSchema-instanc +e="" /> </root>
1) I miss the namespace declaratione in the <root> - element
2) If I try to set the namespace on an attribute manualy like: $writer->emptyTag("node1", ('xsi:nil' => "true")); I get an error: Attribute name 'xsi:nil' contains ':' and the writer terminates.
Is there anyone who can help me? Thanks.In reply to XML::Writer and namespaces by Mr. Ed
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |