Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

How to build a simple XML DTD parser

by jupe (Beadle)
on Apr 25, 2002 at 04:48 UTC ( #161854=perlquestion: print w/replies, xml ) Need Help??

jupe has asked for the wisdom of the Perl Monks concerning the following question:

I want to preface this by saying that I do not have a computer science degree, so I apologize if this question is boneheaded.

I am trying to build a very simple XML DTD parser in Perl. What I can't figure out, though, is if an element in the DTD is the parent element of another in that DTD (and so on and so forth) how I can follow them down for an indeterminate amount of levels.

For example. Lets say there is an element called < Particle > that was the parent of two elements called < Proton > and < Neutron > -- and they in turn were parents for elements < Top > , < Bottom > , < Charm > , and < Beauty > respectively. How can I create a hash with those elements as keys without knowing how many levels down the relationship goes?

I really hope this is making sense, because I feel that it shouldn't be that difficult. I could certainly figure it out if I knew that they were only going to go say 10 levels down, or a hundred, or some finite number, but I won't necessarily have that information.

Any guidance from the kinda and gentle monks here will be greatly appreciated.

jupe

Edit kudra, 2002-05-01 Changed title

Replies are listed 'Best First'.
Re: Simple Programming Problem?
by andreychek (Parson) on Apr 25, 2002 at 12:38 UTC
    Jupe, it sounds as if you may want to look into the XML::Simple module. You can feed it an XML file or string as input, and it can give you back a hash, with the appropriate nested keys.

    Hope that helps!
    -Eric
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2020-10-22 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (227 votes). Check out past polls.

    Notices?