morgon has asked for the wisdom of the Perl Monks concerning the following question:


my application recives XML-documents that contain a declaration (I hope that is the proper term), i.e. they start with something like

<?xml version="1.0" encoding="UTF-8"?>
I now need to get to the encoding-value (not to read the XML but to generate a response with the same encoding).

I parse the XML with XML::LibXML and access the content with XPath (using XML::LibXML::XPathContext) but I cannot find a way to access the declaration.

According to "XML in a Nutshell" the declaration is not addressable via XPath anyway, so I wonder how to do that (apart from the obious regex-hack).

Many thanks!