[Xml-compile] Re: XML::Compile::Schema - Unexpected XML element returned by WRITER

Mark Overmeer solutions at overmeer.net
Thu Aug 20 13:06:29 GMT 2009


* Roman Daniel (roman at daniel.cz) [090820 07:33]:
> As I was looking on the XML::Compile code briefly, what is wrong with  
> $doc->createElementNS($namespaceURI, $qname)
> that you never use it?

I have tried various routes to create the data structures which I wish
for that way.  The problem is that the namespace declarations work
top-down, but the XML structure is created bottom-up.

For instance:
   use XML::LibXML;
   my $ns  = 'http://test';
   my $doc = XML::LibXML::Document->new('1.0', 'UTF8');
   my $e   = $doc->createElementNS($ns, 'a');
   my $f   = $doc->createElementNS($ns, 'b');
   $e->addChild($f);
   $doc->setDocumentElement($e);
   print $doc->toString(1);

Creates
   <?xml version="1.0" encoding="UTF8"?>
   <a xmlns="http://test">
      <b xmlns="http://test"/>
   </a>

which is correct, but I want to create
   <?xml version="1.0" encoding="UTF8"?>
   <y:a xmlns:y="http://test">
      <y:b>
   </y:a>

But I can get this result with
   my $ns  = 'http://test';
   my $doc = XML::LibXML::Document->new('1.0', 'UTF8');
   my $e   = $doc->createElement('y:a');
   my $f   = $doc->createElement('y:b');
   $e->addChild($f);
   $e->setNamespace($ns, 'y', 0);
   $doc->setDocumentElement($e);
   print $doc->toString(1);

If you know an other way, then I am interested in a demo.
-- 
Regards,
               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list