Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

perl script that genarate xml file.

by veerubiji (Sexton)
on Nov 15, 2011 at 17:18 UTC ( #938225=perlquestion: print w/replies, xml ) Need Help??
veerubiji has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I new to generating xml files using perl, How can I generate new xml file using perl script, but the xml file contains this type of data as shown below

<?xml version="1.0" encoding="UTF-8"?> <Detailsofuniversitys xmlns:xsi=" +instance"> <Identification> <Ind>03.20.00</Ind> </Identification> <MetaData> <History> <Entry> <Date>2010-10-19</Date> <Note>IND Created</Note> </Entry> </History> <Status>P</Status> <StoringAndErasing>Not Defined</StoringAndErasing> <StoringAndErasing>Not Defined</StoringAndErasing> </MetaData> <university> <name>svu</name> <location>ravru</location> <branch> <electronics> <student name="xxx" number="12"> <semester number="1"subjects="7" rank="2"/> </student> <student name="xxx" number="15"> <semester number="1" subjects="7" rank="10"/> <semester number="2" subjects="4" rank="1"/> </student> <student name="xxx" number="16"> <semester number="1"subjects="7" rank="2"/> <semester number="2"subjects="4" rank="2"/> </student> </electronics> </branch> </university> <university> <name>sku</name> <location>ANTP</location> <branch> <electronics> <student name="xxx" number="12"> <semester number="3"subjects="6" rank="20"/> </student> <student name="xxx" number="16"> <semester number="1"subjects="9" rank="12"/> <semester number="2"subjects="4" rank="2"/> </student> </section> </electronics> </branch> </university>

Replies are listed 'Best First'.
Re: perl script that genarate xml file.
by davido (Archbishop) on Nov 15, 2011 at 17:33 UTC

    Given that the XML isn't "well formed", I'm not sure why you would want to generate it, much less output it to a file. But in the interest of getting the job done with as little work as possible (in the true spirit of how you asked your question):

    use strict; use warnings; use autodie; my $xml = <<'HERE'; # copy and paste here all the XML you posted # in the node above. HERE open my $fh, '>', 'new.xml'; print $fh $xml; close $fh; #done.

    If you wish to show us what work you've done to get started on the project, what you're doing to prepare the data structure that you wish to dump to XML, and where you're stuck, I'm sure we'll be happy to put more work into helping you with a solution.


      sorry, I have one big file with data like that so I posted only small data, I have 100 university's information like that. I tried as you said it doesn't give any errors but it genarated new xml file with 2KB and I tried to open it internet explorer giving error like this

      The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error +and then click the Refresh button, or try again later. ---------------------------------------------------------------------- +---------- Required white space was missing. Error processing resource 'file:///C +:/files/star/new.xml'. Line 23, Position 26 <semester number="1"subjects="7" rank="2"/> -------------------------^
      can you tel me how to overcome.
        Required white space was missing.

        You have the error message, you have the line of data with the error. Insert the missing whitespace. Whatever is generating your "XML" is sometimes failing to put any space between the "number" and "subjects" attributes.

Re: perl script that genarate xml file.
by choroba (Bishop) on Nov 15, 2011 at 17:29 UTC
    From what do you want to generate the file? Out of nowhere, it can be generated as
Re: perl script that genarate xml file.
by choroba (Bishop) on Nov 15, 2011 at 18:05 UTC
Re: perl script that genarate xml file.
by vinian (Beadle) on Nov 17, 2011 at 09:06 UTC

    Hi, use template, this module can help you


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://938225]
Approved by dwm042
[erix]: advantage of insomnia: having a good look at Jupiter with its four galilean moons

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-04-20 03:16 GMT
Find Nodes?
    Voting Booth?