mcdon_is has asked for the wisdom of the Perl Monks concerning the following question:
Perlmonks In the sample xsl, xml and perl code below I'm trying to test fromDOMtoHash. When I run the code I get You must specify a XML::DOM::Document has the XML parameter at ./test.pl line 21 Although my unserstanding is that the $results arg was a DOM object when it was returned by transform. If I print $result I get XML::DOM::DocumentFragment=ARRAY(0x76b37c) Which seems to clearly indicate it is a DOM object.
XSL
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:test="urn:test"> <xsl:template match="/"> <xsl:variable name="matched" select="test:match_names('title | ti +tulo | titre | titolo', . )" /> <xsl:for-each select="$matched"> <xsl:copy-of select="." /> </xsl:for-each> </xsl:template> </xsl:stylesheet>
XML
<list> <title>System</title> <TituloGrande>Products</TituloGrande> <sublist> <SubTitleOne>Book</SubTitleOne> </sublist> </list>
CODE
#!/bin/perl # import required modules use XML::XSLT; use XML::Hash; use Data::Dumper; # define local variables my $xslfile = "test.xsl"; my $xmlfile = "test.xml"; # create an instance of XSL::XSLT processor my $xslt = XML::XSLT->new ($xslfile, warnings => 0, debug => 0); # transforms the XML file using the XSL style sheet my $results = $xslt->transform ($xmlfile); print $results; # Convertion from a XML::DOM::Document into a HASH my $xml_converter = XML::Hash->new(); my $xml_hash = $xml_converter->fromDOMtoHash($results); # send to output print Dumper($xml_hash); # free up some memory $xslt->dispose();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Hash fromDOMtoHash
by GotToBTru (Prior) on Nov 11, 2014 at 20:42 UTC | |
|
Re: XML::Hash fromDOMtoHash
by Jenda (Abbot) on Nov 14, 2014 at 01:56 UTC |