[Xml-compile] XML to parse does not contain a namespace

Karen Etheridge perl at froods.org
Sat Nov 10 00:45:13 GMT 2012


I am attempting to parse XML with an XSD, but the XML does not contain an
xmlns attribute.  Is there any remedy to tell the compiled reader what the
target namespace is of all the elements being read in?

I've tried various permutations of 'key_rewrite' and 'prefixes' options to
->compile(READER...) but I haven't found the magic combination yet.

The schema does include xmlns and targetNamespace attributes:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.w3schools.com"
    xmlns="http://www.w3schools.com"
   elementFormDefault="qualified">
   ...
</xs:schema>

But the XML to parse looks like:

<?xml version="1.0" encoding="UTF-8"?>
<foo>
   ...
</foo>

and I am building the reader as:
my $schema = XML::Compile::Cache->new($schema_file);
my $reader = $schema->compile(
    READER => pack_type('http://www.w3schools.com', 'foo'),
);

thanks for any hints!

Karen Etheridge
ether at cpan.org



More information about the Xml-compile mailing list