Hi,

I wonder how to add namespace into my xml-attribute declaration: "xsi:nil='true'" I have to create a xml like this:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <node1 xsi:nil="true" /> </root>
But I can't find the right way to do this. My Code:
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;
Gives me this:
<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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.