Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: How do I ignore comments in an xml file when using win32::ole?

by ketanh (Novice)
on Jun 25, 2011 at 19:37 UTC ( #911393=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I ignore comments in an xml file when using win32::ole?
in thread How do I ignore comments in an xml file when using win32::ole?

@choroba, I'm a mere systems engineer trying to parse xml :) I've used xml::simple before, but that doesn't work with the file I have now. So I went with the search that gave me the easiest example to read and follow.

@toolic, Thanks for the example. I didn't know what to do with the xml that you added into the code. I tried reading it in a few ways, didn't help. I have to read a file that I download from a repository and have to load it into my parser
However, thanks to your example, I explored XML::TWIG more and figured out a way to do this.
This link was very helpful
http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html

use warnings; use strict; use XML::Twig; my $file = './test.xml'; my $twig = XML::Twig->new(); $twig->parsefile($file); my $root = $twig->root; foreach my $item ($root->children('Main')){ print $item->att('id').", ".$item->att('name'); print "\n"; }

This gave me the desired output.
1, Item1
2, Item2
4, Item5

@AnomalousMonk, I won't claim to be any sort of expert with xml. To me, if internet explorer grey'ed it out, and Visual SlickEdit "green"ed it out, I take it it's a comment in the XML. :)

Thanks for all your help!


Comment on Re^2: How do I ignore comments in an xml file when using win32::ole?
Download Code
Re^3: How do I ignore comments in an xml file when using win32::ole?
by toolic (Chancellor) on Jun 25, 2011 at 19:45 UTC
    I didn't know what to do with the xml that you added into the code. I tried reading it in a few ways, didn't help. I have to read a file that I download from a repository and have to load it into my parser
    XML::Twig is flexible in that it allows you to parse either a file (as you have done) or a Perl scalar variable (as I have done). Using the latter is merely for the convenience of creating a small self-contained code sample.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2014-09-17 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (91 votes), past polls