I'm having problems producing an XML document with XML::Writer.
the document looks something like...
<ROOT-NS:doctag xmlns:ROOT-NS="http://www.xxxx.com/yyy">
<ROOT-NS:bodytag>
<data xmlns="http://www.xxxx.com/zzz">
<test>ok</test>
</data>
</ROOT-NS:bodytag>
</ROOT-NS:doctag>
Notice the data tag.
It has a namespace attribute with no name.
The Java guys I'm working with say that this is perfectly legal and it is called a default namespace.
When I try and use XML::Writer to do the same thing I always get __NS1 when I don't set a namespace name in my prefix map.
here is my prefix map...
$root_ns = "http://www.xxxx.com/yyy";
$data_ns = "http://www.xxxx.com/zzz";
$prefix_map = {
$root_ns => 'ROOT-NS',
$data_ns => ''
};
This makes my data tag look like...
<__NS1:data xmlns:__NS1="http://www.xxxx.com/zzz">
<test>ok<test>
<__NS1:data>
My XML document object is created with...
$xml = XML::Writer->new(DATA_MODE => 1, DATA_INDENT => 2, NAMESPACES =
+> 1, PREFIX_MAP => $prefix_map);
... and the data tag section looks like...
$xml->startTag([[$data_ns, 'data']]);
$xml->dataElement('test', 'ok');
$xml->endTag();
The perldocs for XML::Writer say...
"
The keys in the hash table are namespace URIs, and
the values are the associated prefixes. If there is
not a preferred prefix for the namespace URI in this
hash, then the module will automatically generate
prefixes of the form "__NS1", "__NS2", etc.
To set the default namespace, use '' for the prefix.
"
What am I doing wrong?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.