Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: XML::Parser Tutorial

by Mike Blume (Initiate)
on Aug 22, 2008 at 18:49 UTC ( [id://706274]=note: print w/replies, xml ) Need Help??


in reply to Re: XML::Parser Tutorial
in thread XML::Parser Tutorial

Jenda, was that in response to my message?
I can't tell if it was or not because it uses the example from the main post, not the one I had.


Mike

Replies are listed 'Best First'.
Re^3: XML::Parser Tutorial
by Jenda (Abbot) on Aug 22, 2008 at 19:58 UTC

    No it was a response to the root node. For your problem ... show us your code. It's true that the Char handler will never be called, but both the Start and End handlers should. In either case you of course can use XML::Rules for that XML as well, specify a handler for the student tag and it will obtain all the attributes. Or, it you do not need to handle the individual <student> tags as you read them, specify student => 'as array', or possibly student => 'by name', in the rules. And handle the array of students in $attr->{student} or access the individual students as $attr->{$name} (depends on the rule you specify for <student>) in the handler for <class>.

      I think I'm going to have to look at the Rules documentation. I'm going to be getting several XML files, some designed w/ the format like I described above and some structured like the conventional way of how XML was originally designed (with inner text).

      I want to have a program that is robust enough to import the XML file, and create either MySQL or PostgreSQL tables add columns to existing tables (should it need this).

      I was hoping that XML::Parser was already set up to be robust enough to get the information, no matter the format, with little programmer intervention (not needing to setup rules). Instead being able to return all the attributes and values for any element, self-closing, or not. :)

      Thanks for the help though,
      Mike

        <tag attr="something"/> IS XML the way it was originaly designed. XML tags are not required to have content, they can very well have only attributes or just appear in the file with no additional info. Do show us the code!

        As far as programmer intervention goes ... you have to intervene somewhere. Of course you can use a module that takes only the XML and gives you a maze of objects and you really do not have to set up anything FOR THIS STEP of the XML processing. But then you have to navigate the maze to get your hands on the data. The first step is easy, but it doesn't take you far.

        Or you can do some work upfront to specify some rules and obtain a data structure that's already tweaked to whatever you need to do with the data later.

        Or you can use a parser that just splits the XML apart and hands you the individual pieces (which is what most styles of XML::Parser do) and you have to handle all the pieces of data immediately as they are found in the file.

        Which style (or a combination of styles) works best for you and the task at hand is something you have to find out. And for XML::Rules ... you can ask it to infer the base set of rules from the DTD or example XMLs. If you do that and leave the ruleset alone, you basicaly end up with the first style. Except that you end up with a HashOfHashesAndArraysOfHashes... instead of objects. But you can tweak the ruleset to skip the stuff you are not interested in, reformat the structure to simplify the searches later, change some static rules to subroutines and handle the data as soon as that particular tag with all its contents is parsed, etc.

        In either case DO show us the failing code using XML::Parser! We do want to see the problem. Or at least I do. Most likely it's something you do, but if there really is a bug in the module I need to know. 'Cause XML::Rules is based on XML::Parser.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-03-28 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found