http://www.perlmonks.org?node_id=1040516


in reply to Nested XML Question

I've been working on this for 12 hours and have gotten just about nowhere. Could somebody provide me some guidance? Anything to get me going in the right direction? I'm completely swimming. Thanks!

Show us what you have and explain what problems you have

Are you having trouble parsing the xml?

I guess you might, but then your "wanted output" doesn't match anything obvious in the xml -- step 1 might be identify output 1 not merely output final :)

use XML::Twig :) it comes with many examples/tutorials, XML::Twig, XML::LibXML, Mojo::DOM ... see Re: The best module for handling xml for examples, walkthroughs, follow my links and the links they link, like these Re: How to grab a portion of file with regex (don't)(parsing html/xml with xpath/twig/dom, because html::parser is low level), Re: How to grab a portion of file with regex (parsing html/xml with xpath/twig/dom, because xml::parser is low level), Re^4: How to grab a portion of file with regex (parsing html/xml with xpath/twig/dom, because ::parser is low level)

Are you having trouble de-ranging the network ranges (or whatever the networking cidr term is) or whatever is you're calculating from the XML ? (the strings don't relate in an obvious way -- maybe obvious to you but most folks don't networks all day)

See converting complex netrange to cidr notation, Net::IP::RangeCompare, regex for classless IP subnets, Managing your IP space with Perl

Replies are listed 'Best First'.
Re^2: Nested XML Question (question_
by zelet (Initiate) on Jun 25, 2013 at 03:46 UTC
    Thanks for the quick reply. I was so neck-deep in this stuff all day I didn't explain it well. For example, the first couple lines of the output file (as related to the original XML I posted) would be this:
    inside-hosts inside-hosts.catchall 10.0.0.0/8 inside-hosts.catchall 192.168.0.0/16 inside-hosts.By Function inside-hosts.By Function.B2B 192.168.0.0/16 inside-hosts.By Function.B2B 192.167.0.0/16 inside-hosts.By Function.B2B 192.166.0.0/16 inside-hosts.By Function.DMZ 192.168.0.1/16 ... etc ... inside-hosts.By Function.Infrastructure inside-hosts.By Function.Infrastructure.Firewalls 192.168.0.1/16 inside-hosts.By Function.Infrastructure.Firewalls 192.168.0.2/16
    My biggest issue is figuring out how to loop through the XML and parse out the name and the IP ranges and create the  name.name.name <tab> IP/range structure.