Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: XML::Parser Tutorial

by Mike Blume (Initiate)
on Aug 23, 2008 at 20:23 UTC ( [id://706449]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^5: XML::Parser Tutorial
by Jenda (Abbot) on Aug 24, 2008 at 12:41 UTC

    <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://706449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found