Hi, I have a very strange problem with a DOMParser object when I want to pass it from one function to the other. First let me give you some code (its quite long, but its needed in order to get my problem across to you, so please bear with me!). I have a main script called "testXerces.pl": -------------------------------------------------- #!/usr/bin/perl
use strict; use testXercesModule; use XML::Xerces; use XML::Xerces::DOMParse; my $page = '<?xml version="1.0"?> <!DOCTYPE paymentService PUBLIC "-//Bibit//DTD Bibit PaymentService v1//EN" "http://dtd.bibit.com/paymentService_v1.dtd"> <paymentService merchantCode="ACME" version="1.2"> <reply> <error code="2"><![CDATA[Empty body in message.]]></error> </reply> </paymentService>'; my($_parser)=&initParser(); my($rresult,$contents)=&indirectReadXMLFile($_parser,$page); print "contents=$contents.\n"; if ($rresult ne "1") { print "x could not parse the input: \"$rresult\".\n"; } else { my($messageType)=$contents->getDocumentElement()->getElementsByTagName(" *")->item(0)->getNodeName(); print "messageType in main=$messageType.\n"; } print "finished!\n\n"; exit; -------------------------------------------------------- And I have a helper module called "testXercesModule.pm" which I "use" in the main script: -------------------------------------------------------- use strict; use XML::Xerces; use XML::Xerces::DOMParse; sub indirectReadXMLFile { my($_parser,$page)=@_; # my($_parser)=&initParser(); my($tempfilename)="/tmp/DOM-temp-file".$$.".xml"; unlink $tempfilename; print "page=\n$page\n-------------------------\n"; if (!(open(TEMPFILE,">$tempfilename"))) { die "x error: could not create temp file: $!\n\n"; } print TEMPFILE $page; close TEMPFILE; my($rresult,$contents)=&readXMLFile($tempfilename,$_parser); unlink $tempfilename; if ($rresult eq "1") { my($messageType)=$contents->getDocumentElement()->getElementsByTagName(" *")->item(0)->getNodeName(); print "messageType in sub=$messageType.\n"; } return($rresult,$contents); } sub initParser { # Initialize a new parser object: my($newParser)=XML::Xerces::DOMParser->new(); $newParser->setValidationScheme($XML::Xerces::DOMParser::Val_Auto); $newParser->setDoNamespaces(0); $newParser->setCreateEntityReferenceNodes(1); $newParser->setDoSchema(0); my($ERROR_HANDLER) = XML::Xerces::PerlErrorHandler->new(); $newParser->setErrorHandler($ERROR_HANDLER); return($newParser); } sub readXMLFile { my($file,$parser)=@_; my($doc)=''; return("no file name was specified",$doc) if ($file eq ''); return("the specified file does not exist",$doc) if (!(-e $file)); # Open the file and parse it: eval { $parser->parse (XML::Xerces::LocalFileInputSource->new($file)); }; if ($@) { if (ref $@) { return($@->getMessage(),$doc); } else { if ($@ ne "1") { return($@,$doc); } else { return("0",$doc); } } } $doc = $parser->getDocument (); return("1",$doc); } 1; -------------------------------------------------------- In this version of the code, my main script calls the sub "indirectReadXMLFile", passing to it a reference to a DOMParser object and an XML string. This works just fine. However - and this is what confuses me A LOT - if I change the "indirectReadXMLFile" sub so that its only input variable becomes the XML string ($page), and uncomment the line # my($_parser)=&initParser(); in "indirectReadXMLFile" - so that this sub now takes care of creating a new parser object itself - the script runs into a Segmentation Fault and dumps a core!! Can anyone tell me why this happens? I'm totally confused about this!! What is it that I'm missing here?? Regards, Bjorn Hermans. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
