Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Generate XML code from a xschema

by bcochofel (Novice)
on Nov 13, 2006 at 14:47 UTC ( #583717=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I need to access a mysql db to retrieve data and then generate a xml with the results. I need to generate a xml using a xschema file. How can I do this? I'm new to Perl and XML... My code can get results using dbi and I wrote an cgi script to use with my web server. I got everything to work and get the results expected in my browser... Now I would like to generate a xml with this results but I don't know where to start. Thanks, Bruno

Update fixed typo in the title larsen

Replies are listed 'Best First'.
Re: Generate XML code from a xschema
by davorg (Chancellor) on Nov 13, 2006 at 16:00 UTC

    Personally, I'd use the Template Toolkit in the way that I described in this article. There's a more detailed example in the XML chapter of the Badger book.


    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Well, I gave you about all that I have... I will receive an xsd file to validate my xml output. The output will be the results from some SQL query to a MySQL DB. This will be running under Apache + mod_perl (that I have configured and it's working). For now I'm just trying to figure out where to start because I will need this and I don't know how to do it. Using DBI and CGI module it's what I'm learning for now. Thanks for the replies.
Re: Generate XML code from a xschema
by madbombX (Hermit) on Nov 13, 2006 at 15:57 UTC
    If you take a look at the XML, that should be a good place to start. It won't immediately do XML generation, but there are tools such as XML::Simple and XML::Twig that can be handy for you. Its difficult to tell you anything specific since you didn't provide any specific information.

    Also, in the future, take a stab at getting what you want. When you get stuck, post what you have attempted and we will do our best to show you some options. But showing some effort is key here here. It would also help if you provided us with some example of what you wanted to do.

Re: Generate XML code from a xschema
by porta (Sexton) on Nov 13, 2006 at 15:54 UTC
    If you're getting the data from a DB (and I'm assuming all the data has pretty much the same format/same xml elements) I think that one really easy option could be to use HTML::Template (for example) to create your XML file easily and without to struggle with any XML module. Of course this can sound like a pretty lame option, but It has worked for me in the past. Quick and dirty. NOTE. If your data in the DB has html code, you'll want to escape html entities to avoid a malformed xml file. Hope this works for you.
Re: Generate XML code from a xschema
by john_oshea (Priest) on Nov 13, 2006 at 23:12 UTC

    If you just want to generate some dummy xml from a schema, you could use OxygenXML's editor to do this. This is totally non-Perl, but if it's a one-off it may be quicker/easier than writing yourself some code. OxygenXML is relatively cross-platform, has a trial license available, but requires working Java, which may or may not be an issue.

    Apologies if I've misunderstood your question.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://583717]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-03-22 04:07 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.