Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Error decoding XML

by Hammy (Scribe)
on Jan 24, 2005 at 16:19 UTC ( #424620=perlquestion: print w/replies, xml ) Need Help??
Hammy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am a bit puzzled. I have a piece of code that decodes an XML stream and I am getting an error that tells me 'file does not exist'. I am getting the file does not exist on the XMLin line. This code has worked like a charm for months and now it just stopped. Does anyone have any suggestions? Thank you in advance!
use DBI; use CGI; &set_content(); &callFunctions(); sub callFunctions { my $xml = '<hdsso><hpid>--------</hpid><pin&g +t;abcbs-hd</pin><fname>--------</fname><mname&gt +;</mname><lname>-------</lname><dob>-------&l +t;/dob><email>-------</email><ls>----------</ +ls><ws>---------</ws></hdsso>'; use XML::Simple; $XMLref = XMLin($xml, suppressempty => ''); } sub set_content { $q = new CGI; print $q->header( -type => 'text/html',-P3P => 'CP="NOI ADM DEV PS +Ai COM NAV OTRo STP IND DEM" policyref="/w3c/p3p.xml"'); use CGI::Carp qw(fatalsToBrowser carpout); if ( open(LOG,">>errors.log") ) { carpout(LOG); } } 1;

Replies are listed 'Best First'.
Re: Error decoding XML
by tinita (Parson) on Jan 24, 2005 at 16:27 UTC
    and I am getting an error that tells me 'file does not exist'.
    i guess it tells you:
    File does not exist: <hdsso><hpid>...

    your $xml isn't XML. xml has < and > instead of &lt; and &gt;

      Indeed. XML::Simple treats string arguments other than those containing a < eventually followed by a > as filenames, not XML documents. XML documents SHOULD (as opposed to MUST) start with a decleration (looks like <?xml version="1.0"?>), so it's not a bad way of differentiating file names from XML strings.

        Does this mean if I put the string to start my XML, it should work OK? I tried just putting that string at the beginning and it still gave me a file does not exist error. The data I am getting I am receiving from someone else. I can add data to it or remove data from it, but I can not change the structure of the data.

        This is a hosted box so there was probably a version upgrade recently (only explination I can come up with). Any suggestions on what else I should use?
Re: Error decoding XML
by dragonchild (Archbishop) on Jan 24, 2005 at 16:21 UTC
    What changed in your setup? Did you upgrade anything? Move from one box to another?

    I'm betting that the version of XML::Simple has changed, either up or down, from when it worked to now.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Error decoding XML
by gmpassos (Priest) on Jan 24, 2005 at 23:17 UTC
    my $xml = '&lt;hdsso&gt;&lt;hpid&gt;--------&lt;/hpid&gt;&lt;pin&gt;ab +cbs-hd&lt;/pin&gt;&lt;fname&gt;--------&lt;/fname&gt;&lt;mname&gt;&lt +;/mname&gt;&lt;lname&gt;-------&lt;/lname&gt;&lt;dob&gt;-------&lt;/d +ob&gt;&lt;email&gt;-------&lt;/email&gt;&lt;ls&gt;----------&lt;/ls&g +t;&lt;ws&gt;---------&lt;/ws&gt;&lt;/hdsso&gt;';
    The code above is not XML! Youn only have a string with basic entities.

    If you want to use this 3rd part data, you can use the XML parser to fix the data as a content of an element, than use the content as a normal data input for another xml:

    use XML::Smart ; my $bad_xml = '&lt;hdsso&gt;&lt;hpid&gt;--------&lt;/hpid&gt;&lt;pin +&gt;abcbs-hd&lt;/pin&gt;&lt;fname&gt;--------&lt;/fname&gt;&lt;mname& +gt;&lt;/mname&gt;&lt;lname&gt;-------&lt;/lname&gt;&lt;dob&gt;------- +&lt;/dob&gt;&lt;email&gt;-------&lt;/email&gt;&lt;ls&gt;----------&lt +;/ls&gt;&lt;ws&gt;---------&lt;/ws&gt;&lt;/hdsso&gt;'; my $xml_obj_fix = new XML::Smart( "<data>$bad_xml</data>" ,'html') ; + my $xml_obj_ok = new XML::Smart( $xml_obj_fix->{data} ,'html') ; print $xml_obj_ok->data ;
    The output:
    <?xml version="1.0" encoding="iso-8859-1" ?> <?meta name="GENERATOR" content="XML::Smart/1.6.9 Perl/5.006001 [MSWin +32]" ?> <root> <_1/> <hpid>--------</hpid> <pin>abcbs-hd</pin> <fname>--------</fname> <mname/> <lname>-------</lname> <dob>-------</dob> <email>-------</email> <ls>----------</ls> <ws>---------</ws> </root>

    Graciliano M. P.
    "Creativity is the expression of liberty".

Re: Error decoding XML
by inman (Curate) on Jan 25, 2005 at 11:43 UTC
    As a general point you could assign $xml using a here doc. e.g.
    my $xml = <<XML; <hdsso> <hpid>--------</hpid> <pin>abcbs-hd</pin> <fname>--------</fname> <mname/> <lname>-------</lname> <dob>-------</dob> <email>-------</email> <ls>----------</ls> <ws>---------</ws> </hdsso> XML

    Unrelated to the question but you might want to set the P3P header usng the webservers 'add header' facility. The P3P cookie policy is expected to be set for the whole server rather than a particular URL.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://424620]
Approved by tinita
[atcroft]: Lady_Aleena: So you are shoving the disparate data into a structure and returning the structure, so you can run it through a (probably simpler) routine that displays only?
[Lady_Aleena]: atcroft, that is the goal.
[Lady_Aleena]: atcroft, this is the last of the printing modules I am going to make stop printing, I think.
[Lady_Aleena]: It will leave me with 8 out of 138 modules that print something.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2017-05-29 02:37 GMT
Find Nodes?
    Voting Booth?