Subject: | problem with namespaces |
I've got an error while trying to read document that has been produced
with XML::Compile. I suppose that problem appears because there are no
active namespaces for the xml nodes ( or I just have missed something ).
Here is a short snippet demonstrating the problem:
use XML::Compile::Cache;
use XML::LibXML;
my $s = XML::Compile::Cache->new(
prefixes => { atk => 'http://example.com/2012/05/atk' } ,
key_rewrite => 'PREFIXED'
);
my $schemas = XML::LibXML->load_xml( string => <<XML );
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns="http://example.com/2012/05/atk"
targetNamespace="http://example.com/2012/05/atk" >
<xsd:element name="test" type="xsd:string"/>
</xsd:schema>
XML
$s->addSchemas( $schemas );
my $doc = XML::LibXML::Document->new( '1.0' );
my $writer = $s->compile('WRITER', 'atk:test' );
$doc->setDocumentElement( $writer->( $doc, "12" ));
warn $doc->toString(2);
my $reader = $s->compile('READER', 'atk:test' );
eval {
# throws error
$reader->( $doc );
};
# that's OK
my $new_doc = XML::LibXML->load_xml( string => $doc->toString );
$reader->( $new_doc );
# what's the difference:
# there is no namespace for the root node
#
warn $doc->documentElement->namespaceURI; # has it
warn $new_doc->documentElement->namespaceURI; # has no