Help required in Building an XML using SAX Parser in perl

I want to use sax parser for my application as i have 5 Lakhs of data.

I have the xml file like this

<Nodes>
	<Node>
	 <NodeName>Company</NodeName>
     <File>employee_details.csv</File>
     <data>employee_data.txt</data>
	 <Node>
	 <NodeName>dummy</NodeName>
     <File>employee_details1.csv</File>
     <data>employee_data1.txt</data>
	</Node>
	</Node>
</Nodes>
#Contents of employee_data.txt
Empname,Empcode,EmpSal:Currency,Empaddr
#Contents of employee_details.csv (like this huge data)
Alex,A001,1000:USD,Bangalore
Aparna,B001,1000:RUBEL,Bombay
#Contents of employee_data1.txt
phone,fax
#Contents of employee_details1.csv (like this huge data)
44568889,123345656
23232323,454545757

I have to process these and print it in the xml format. I want to use SAX Parser.

Output:

<Company>
<Empname>Alex</Empname>
<Empcode>A001</Empcode>
<EmpSal=USD>1000</EmpSal>
<Empaddr>Bangalore</Empaddr>
<phone>44568889</phone>
<fax>123345656</fax>
</Company>
<Company>
<Empname>Aparna</Empname>
<Empcode>B001</Empcode>
<EmpSal=RUBEL>1000</EmpSal>
<Empaddr>Bombay</Empaddr>
<phone>23232323</phone>
<fax>454545757</fax>
</Company>

I am very new to perl parser so finding it difficulty in building an xml tree.

Since there is huge amount of data parsing and putting the parsed content will be better using an Sax parser as read by posts.

How can i get the above output using an SAX parser?

Help is very much required.

Regards
Vanitham

Here is a useful tutorial: XML for Perl developers, Part 2: Advanced XML parsing techniques using Perl

Hi,

Thanks for your mail. Will go through the tutorials and get back to u for further help.

Regards
Vanitha

---------- Post updated at 04:38 AM ---------- Previous update was at 02:29 AM ----------

Hi,

I just went through the tutorials but i did not understand how to handle and write the events i.e how to get the main node and parse the file and create an xml tree as mentioned above mail.

Help is very much required?

Regards
Vnitha

I was going to ask what a Lakh is, but I found it.

Does the original .xml file really have nested <Node>s?

Are there only four filenames that are replicated for every employee? Or are these just examples?

Hi,

It is <Nodes> not <Node>s.

These are just example u can say a sample file more records are there.

Regards
Vanitha

The example has
<Node>
...
<Node>
...
</Node>
</Node>

I call that "nested <Node>s".
It seems odd and surprising, so I'm just asking if it's real or a typo.

Hi,

The main nodes is Employee and others are under that node.

Is there any possibility of building an xml tree using an sax parser?

Regards
Vanitha

I think so. But I looked at that and thought it would be fairly straightforward to do it with a shell script, and I actually spent some time working on one.

But it's more complex than it looks. And I suspected the nested <Nodes>s were an incorrect transcription. And I didn't understand if there are only four filenames that are replicated for every employee, or if there are multiples of four.

If it were my project, I think I would continue and actually use the shell script. But then I'm very comfortable with shell scripts whereas I would be stumbling along with the SAX parser.

Hi,

It is the just junk i have send u.

If u can provide the snippet for shell script that would be really great for this scenario.

I am very new to shell scripting.

The filename varies for each of the nodes and there are thousands of nodes with different details and filenames for example (aaa.txt, bbb.txt .....) and the corresponding csv files.

So how can i proceed further?

Please do let me know.

Regards
Vanitha