Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl: the Markov chain saw
 
PerlMonks  

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

by BrowserUk (Pope)
on Jan 14, 2012 at 22:09 UTC ( #947914=note: print w/ replies, xml ) Need Help??


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

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?


Comment on Re^4: Is there any XML reader like this?
Select or Download Code
Re^5: Is there any XML reader like this?
by tobyink (Abbot) on Jan 15, 2012 at 08:35 UTC

    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?

        What if the addition was:

        <ip note="UNDER NO CIRCUMSTANCES USE THIS IP ON PAIN OF SUBSTANTIAL LEGAL 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

        And your XML::Simple example with NoAttr => 1 will also blithely process in just the same way as every other IP it finds. What exactly was your point?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-04-20 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls