Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Is there any XML reader like this?

by tobyink (Abbot)
on Jan 14, 2012 at 20:43 UTC ( #947913=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Is there any XML reader like this?
in thread Is there any XML reader like this?

You simply need to add one simple option

And that helps you for precisely five minutes until someone adds this to the file:

  <ip assignment="temporary">10.0.0.101</ip>

And then all your code which assumes stations have IP addresses which are arrayrefs of strings breaks again.


Comment on Re^3: Is there any XML reader like this?
Re^4: Is there any XML reader like this?
by BrowserUk (Pope) on Jan 14, 2012 at 22:09 UTC
    then all your code which assumes stations have IP addresses which are arrayrefs of strings breaks again.

    Nope. This:

    #! perl -slw use strict; use Data::Dump qw[ pp ]; use XML::Simple; my $xml = XMLin( \*DATA, ForceArray => [ 'ip' ], NoAttr => 1 ); pp $xml; __DATA__ <servers> <station18> <ip>10.0.0.101</ip> <ip>10.0.1.101</ip> <ip>10.0.0.102</ip> <ip>10.0.0.103</ip> <ip>10.0.1.103</ip> </station18> <station19> <ip>10.0.0.111</ip> <ip>10.0.1.111</ip> <ip>10.0.0.112</ip> <ip>10.0.0.113</ip> <ip>10.0.1.113</ip> </station19> <station17> <ip assignment="temporary">10.0.0.101</ip> <ip>10.0.0.121</ip> </station17> </servers>

    Produces this::

    C:\test>junk44 { station17 => { ip => ["10.0.0.101", "10.0.0.121"] }, station18 => { ip => [ "10.0.0.101", "10.0.1.101", "10.0.0.102", "10.0.0.103", "10.0.1.103", ], }, station19 => { ip => [ "10.0.0.111", "10.0.1.111", "10.0.0.112", "10.0.0.113", "10.0.1.113", ], }, }

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      I don't dispute that there is yet another XML::Simple option that can fix things again.

      My point is that things appear to work for a while, and then a small change to your input data breaks everything, so you need to alter your code. And then another change to the input data requires another code change.

      One of the major reasons people use config files is so that they can avoid having to make changes to running code when, say, a new IP address is assigned.

        yet another XML::Simple option

        That's a joke right?

        XML::Simple has two entry points and 29 parse time options -- most of which you will never use -- that are all documented on a single page.

        XML::LibXML has 26 entrypoints and 40+ constructor options mentioned -- note: not "documented" -- on just the parser page. And there are hundreds more entrypoint 'mentions' plus innumerable importable constants scattered across another 31 more pages.

        One of the major reasons people use config files is so that they can avoid having to make changes to running code when, say, a new IP address is assigned.

        Just use the required parsing options from the get-go and no change is required.

        Of course, if the input file specifications change during the life of the program, then you will have to change program.

        But modifying one program line after a substantial modification to the file format is hardly onerous.

        If you are trying to claim that you wouldn't have to modify your program that used LibXML for a similar change, you are kidding yourself.

        What if the addition was:

        <ip note="UNDER NO CIRCUMSTANCES USE THIS IP ON PAIN OF SUBSTANTIAL LE +GAL REPRISALS; INCLUDING EXTRADITION AND LIFE IMPRISONMENT">67.215.65 +.132</ip>

        which your LibXML program will blithely process in just the same way as every other IP it finds -- including perhaps attempting to access it which may well be construed as attempted hacking in some quarters -- without noticing a thing.

        Personally, I prefer that my program either ignored that IP or issued a warning or error. At least until I'd had a chance to see what changed.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re^4: Is there any XML reader like this?
by Jenda (Abbot) on Jan 15, 2012 at 00:01 UTC

    Which may very well be the right thing to do. The format of the data changed, is it really safe to snip out the bits we did expect and ignore the rest?

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Re^4: Is there any XML reader like this?
by ashok.g (Beadle) on Jan 15, 2012 at 14:57 UTC
    Getting the following errorNot an ARRAY reference at ProcessStatus.pl line 44. when I have this option that will have stations mixed like:
    <station20> <user>netcool</user> <process assignment="temporary">some text</process> </station20> <station19> <user>netcool</user> <process>nco_objserv</process> <process>nco_p_mttrapd</process> </station19>

    Code snippet....
    my $xml = XMLin("PROCESS.CONF"); ...... foreach $process ( @{ $xml->{$server}{process} } ) .....
    Anything missing here?

    Thanks,
    Ashok
      Appreciate any help here!

      Thanks,
      Ashok
        Thanks.
        I will work on this and update you.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-11-29 03:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls