|
-
December 27th, 2005, 09:21 PM
#1
Convert Textfile into XML
Problem 1:
How to remove the following BOLD string from a textfile. and convert the unbold string into an XML file. and read the XML into a datagrid.
pROBLEM 2:
Due to the different format of textfile (Sample file 1 & 2), how to pull out only the XML information and remove the unwanted information?
Problem 3:
Sample file 2 has a element different from Sample file 1. in the parent element of sample file 1 is "Record" , in sample file 2 is "ARGC-ARGU" or "Pregate". It need to be replace with "RECORD" for both the "ARGC-ARGU" and "Pregate" from the start element and end element.
I need it to work with a function --- to read a logging textfile with some XML information inside as well as other unwanted information. this function is to delete the unwanted information in the textfile and pull the XML information out and parse into an XML file named "file.xml". Then it will read from the file.xml instead of the texfile and parse the data into the datagrid.
FILE SAMPLES
Code:
sample file 1:
2005-11-21 00:01:40,678 [ExecuteThread: '1' for queue: 'default'] INFO - message received...
2005-11-21 00:01:40,749 [ExecuteThread: '1' for queue: 'default'] INFO - The XML message **************<berth_allocation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><system_c>BPMS</system_c><trans_c>BPMSMessage</trans_c><trans_dt>2005-11-21T00:01:40.219+08:00</trans_dt><message><record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><func_c>U</func_c><vv_c>15336</vv_c><vessel_m>GEMARTRANS PIONEER</vessel_m><abbr_vessel_m>GMT PIONEER</abbr_vessel_m><voyage_out_n>47N</voyage_out_n><abbr_voyage_out_n>47N</abbr_voyage_out_n><voyage_in_n>46S</voyage_in_n><abbr_voyage_in_n>46S</abbr_voyage_in_n><berth_seq_n>1</berth_seq_n><etb_dt>2005-11-21T12:00:00.000+08:00</etb_dt><old_etb_dt>2005-11-21T12:00:00.000+08:00</old_etb_dt><etu_dt>2005-11-22T09:30:00.000+08:00</etu_dt><old_etu_dt>2005-11-22T09:00:00.000+08:00</old_etu_dt><terminal_c>K</terminal_c><old_terminal_c>K</old_terminal_c><position_from_n>625</position_from_n><position_to_n>760</position_to_n><wharfside_i> </wharfside_i><remark_x>t/u.fast steam @ 1200hrs</remark_x><qc_assignment><terminal_c>K</terminal_c><qc_n>77</qc_n><start_dt>2005-11-21T12:00:00.000+08:00</start_dt><end_dt>2005-11-22T09:30:00.000+08:00</end_dt><operation_c>2</operation_c><qc_position_n>2</qc_position_n><qc_m>B</qc_m></qc_assignment><qc_assignment><terminal_c>K</terminal_c><qc_n>78</qc_n><start_dt>2005-11-21T12:00:00.000+08:00</start_dt><end_dt>2005-11-22T09:30:00.000+08:00</end_dt><operation_c>2</operation_c><qc_position_n>1</qc_position_n><qc_m>A</qc_m></qc_assignment><qc_rate_q>18.0</qc_rate_q><qc_intensity_q>1.6</qc_intensity_q><location_from_c>PEBGA</location_from_c><location_to_c>SEAE</location_to_c><berth_pilot_i>true</berth_pilot_i><unberth_pilot_i>true</unberth_pilot_i><delay_c>Q</delay_c><status_c>U</status_c><btr_dt>2005-11-21T13:00:00.000+08:00</btr_dt><priority_c>B6</priority_c><scheme_qualify_i>X</scheme_qualify_i><section_n>4</section_n><berth_m>K22</berth_m></record></message><user_id_n>ctleow</user_id_n></berth_allocation>
2005-11-21 00:01:40,756 [ExecuteThread: '1' for queue: 'default'] INFO - Root Node is [berth_allocation]
2005-11-21 00:01:40,761 [ExecuteThread: '1' for queue: 'default'] INFO - XML messages retrieved:<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><func_c>U</func_c><vv_c>15336</vv_c><vessel_m>GEMARTRANS PIONEER</vessel_m><abbr_vessel_m>GMT PIONEER</abbr_vessel_m><voyage_out_n>47N</voyage_out_n><abbr_voyage_out_n>47N</abbr_voyage_out_n><voyage_in_n>46S</voyage_in_n><abbr_voyage_in_n>46S</abbr_voyage_in_n><berth_seq_n>1</berth_seq_n><etb_dt>2005-11-21T12:00:00.000+08:00</etb_dt><old_etb_dt>2005-11-21T12:00:00.000+08:00</old_etb_dt><etu_dt>2005-11-22T09:30:00.000+08:00</etu_dt><old_etu_dt>2005-11-22T09:00:00.000+08:00</old_etu_dt><terminal_c>K</terminal_c><old_terminal_c>K</old_terminal_c><position_from_n>625</position_from_n><position_to_n>760</position_to_n><wharfside_i> </wharfside_i><remark_x>t/u.fast steam @ 1200hrs</remark_x><qc_assignment><terminal_c>K</terminal_c><qc_n>77</qc_n><start_dt>2005-11-21T12:00:00.000+08:00</start_dt><end_dt>2005-11-22T09:30:00.000+08:00</end_dt><operation_c>2</operation_c><qc_position_n>2</qc_position_n><qc_m>B</qc_m></qc_assignment><qc_assignment><terminal_c>K</terminal_c><qc_n>78</qc_n><start_dt>2005-11-21T12:00:00.000+08:00</start_dt><end_dt>2005-11-22T09:30:00.000+08:00</end_dt><operation_c>2</operation_c><qc_position_n>1</qc_position_n><qc_m>A</qc_m></qc_assignment><qc_rate_q>18.0</qc_rate_q><qc_intensity_q>1.6</qc_intensity_q><location_from_c>PEBGA</location_from_c><location_to_c>SEAE</location_to_c><berth_pilot_i>true</berth_pilot_i><unberth_pilot_i>true</unberth_pilot_i><delay_c>Q</delay_c><status_c>U</status_c><btr_dt>2005-11-21T13:00:00.000+08:00</btr_dt><priority_c>B6</priority_c><scheme_qualify_i>X</scheme_qualify_i><section_n>4</section_n><berth_m>K22</berth_m></record>
2005-11-21 00:03:04,799 [ExecuteThread: '3' for queue: 'default'] INFO - message received...
2005-11-21 00:03:04,799 [ExecuteThread: '3' for queue: 'default'] INFO - The XML message **************<berth_allocation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><system_c>BPMS</system_c><trans_c>BPMSMessage</trans_c><trans_dt>2005-11-21T00:03:04.535+08:00</trans_dt><message><record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><func_c>C</func_c><vv_c>10786</vv_c><vessel_m>KOTA WANGI</vessel_m><abbr_vessel_m>KOTA WANGI</abbr_vessel_m><voyage_out_n>WGI869</voyage_out_n><abbr_voyage_out_n>WGI869</abbr_voyage_out_n><voyage_in_n>WGI869</voyage_in_n><abbr_voyage_in_n>WGI869</abbr_voyage_in_n><berth_seq_n>1</berth_seq_n><etb_dt>2005-11-23T06:00:00.000+08:00</etb_dt><old_etb_dt>2005-11-23T06:00:00.000+08:00</old_etb_dt><etu_dt>2005-11-24T00:00:00.000+08:00</etu_dt><old_etu_dt>2005-11-24T00:00:00.000+08:00</old_etu_dt><terminal_c>K</terminal_c><old_terminal_c>K</old_terminal_c><position_from_n>600</position_from_n><position_to_n>785</position_to_n><wharfside_i>P</wharfside_i><qc_rate_q>22.0</qc_rate_q><qc_intensity_q>2.3</qc_intensity_q><location_from_c>PEBGA</location_from_c><location_to_c>SEAE</location_to_c><berth_pilot_i>true</berth_pilot_i><unberth_pilot_i>true</unberth_pilot_i><delay_c> </delay_c><status_c>U</status_c><btr_dt>2005-11-23T06:00:00.000+08:00</btr_dt><priority_c>B6</priority_c><scheme_qualify_i>X</scheme_qualify_i><section_n>4</section_n><berth_m>K18</berth_m></record></message><user_id_n>BA</user_id_n></berth_allocation>
2005-11-21 00:03:04,805 [ExecuteThread: '3' for queue: 'default'] INFO - Root Node is [berth_allocation]
2005-11-21 00:03:04,811 [ExecuteThread: '3' for queue: 'default'] INFO - XML messages retrieved:<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><func_c>C</func_c><vv_c>10786</vv_c><vessel_m>KOTA WANGI</vessel_m><abbr_vessel_m>KOTA WANGI</abbr_vessel_m><voyage_out_n>WGI869</voyage_out_n><abbr_voyage_out_n>WGI869</abbr_voyage_out_n><voyage_in_n>WGI869</voyage_in_n><abbr_voyage_in_n>WGI869</abbr_voyage_in_n><berth_seq_n>1</berth_seq_n><etb_dt>2005-11-23T06:00:00.000+08:00</etb_dt><old_etb_dt>2005-11-23T06:00:00.000+08:00</old_etb_dt><etu_dt>2005-11-24T00:00:00.000+08:00</etu_dt><old_etu_dt>2005-11-24T00:00:00.000+08:00</old_etu_dt><terminal_c>K</terminal_c><old_terminal_c>K</old_terminal_c><position_from_n>600</position_from_n><position_to_n>785</position_to_n><wharfside_i>P</wharfside_i><qc_rate_q>22.0</qc_rate_q><qc_intensity_q>2.3</qc_intensity_q><location_from_c>PEBGA</location_from_c><location_to_c>SEAE</location_to_c><berth_pilot_i>true</berth_pilot_i><unberth_pilot_i>true</unberth_pilot_i><delay_c> </delay_c><status_c>U</status_c><btr_dt>2005-11-23T06:00:00.000+08:00</btr_dt><priority_c>B6</priority_c><scheme_qualify_i>X</scheme_qualify_i><section_n>4</section_n><berth_m>K18</berth_m></record>
sample file 2:
00:00:07 weblogic server=t3://cng3wls8:80
00:00:07 Queue key, Queue Name=[GMS_Q,jms/citos/gms/HssQueue]
00:00:17 weblogic server=t3://cng3wls8:80
00:00:17 Queue key, Queue Name=[GMS_Q,jms/citos/gms/HssQueue]
00:00:27 weblogic server=t3://cng3wls8:80
00:00:27 Queue key, Queue Name=[GMS_Q,jms/citos/gms/HssQueue]
00:00:37 weblogic server=t3://cng3wls8:80
00:00:37 Queue key, Queue Name=[GMS_Q,jms/citos/gms/HssQueue]
00:00:37 Sending Message :<ARGC-ARGU xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<trans_id>ARGC</trans_id>
<sys_prefix>GSYS</sys_prefix>
<terminal_id>G31</terminal_id>
<lane_ts>2</lane_ts>
<version>B</version>
<sno>1105891123</sno>
<ariv_dt>200501162358</ariv_dt>
<gate>3</gate>
<lane>02</lane>
<opr_logon>PD$SDI </opr_logon>
<card_no>014797</card_no>
<nom_hlr_cr_no> </nom_hlr_cr_no>
<nom_pass_ind>Y</nom_pass_ind>
<pass_no>411924</pass_no>
<nric_no>1717951I</nric_no>
<auto_confirm>Y</auto_confirm>
<out_gate_no>4</out_gate_no>
<out_lane_no>12</out_lane_no>
<late_i> </late_i>
<pm_no>IPM 899 </pm_no>
<pm_tag_install>Y</pm_tag_install>
<pm_tag_det>Y</pm_tag_det>
<ch_type>98</ch_type>
<ch_ulw>11520</ch_ulw>
<wt_reading>26660</wt_reading>
<empty_i>N</empty_i>
<in1_cntr_ind>Y</in1_cntr_ind>
<in1_cntr_no>KLFU 9061610 </in1_cntr_no>
<in1_dir_ind>N</in1_dir_ind>
<in1_rej_reason> </in1_rej_reason>
<in1_act_wt>05380</in1_act_wt>
<in1_act_wt_class>L</in1_act_wt_class>
<in1_out_act_wt>11330</in1_out_act_wt>
<in1_out_dt>200501162349</in1_out_dt>
<in1_survey>AD </in1_survey>
<in1_tt_blk> </in1_tt_blk>
<in1_cnrs_ind> </in1_cnrs_ind>
<in1_cnrs_no> </in1_cnrs_no>
<in1_eir_in_no>163128347</in1_eir_in_no>
<in1_yd_assgn>PC080102030301</in1_yd_assgn>
<in1_faded_cntr_ind>N</in1_faded_cntr_ind>
<in1_pos_ind> </in1_pos_ind>
<in2_cntr_ind> </in2_cntr_ind>
<in2_cntr_no> </in2_cntr_no>
<in2_dir_ind> </in2_dir_ind>
<in2_rej_reason> </in2_rej_reason>
<in2_act_wt> </in2_act_wt>
<in2_act_wt_class> </in2_act_wt_class>
<in2_out_act_wt> </in2_out_act_wt>
<in2_out_dt> </in2_out_dt>
<in2_survey> </in2_survey>
<in2_tt_blk> </in2_tt_blk>
<in2_cnrs_ind> </in2_cnrs_ind>
<in2_cnrs_no> </in2_cnrs_no>
<in2_eir_in_no> </in2_eir_in_no>
<in2_yd_assgn> </in2_yd_assgn>
<in2_faded_cntr_ind> </in2_faded_cntr_ind>
<in2_pos_ind> </in2_pos_ind>
</ARGC-ARGU>
00:00:37 Msg send to Queue=[<ARGC-ARGU xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<trans_id>ARGC</trans_id>
<sys_prefix>GSYS</sys_prefix>
<terminal_id>G31</terminal_id>
<lane_ts>2</lane_ts>
<version>B</version>
<sno>1105891123</sno>
<ariv_dt>200501162358</ariv_dt>
<gate>3</gate>
<lane>02</lane>
<opr_logon>PD$SDI </opr_logon>
<card_no>014797</card_no>
<nom_hlr_cr_no> </nom_hlr_cr_no>
<nom_pass_ind>Y</nom_pass_ind>
<pass_no>411924</pass_no>
<nric_no>1717951I</nric_no>
<auto_confirm>Y</auto_confirm>
<out_gate_no>4</out_gate_no>
<out_lane_no>12</out_lane_no>
<late_i> </late_i>
<pm_no>IPM 899 </pm_no>
<pm_tag_install>Y</pm_tag_install>
<pm_tag_det>Y</pm_tag_det>
<ch_type>98</ch_type>
<ch_ulw>11520</ch_ulw>
<wt_reading>26660</wt_reading>
<empty_i>N</empty_i>
<in1_cntr_ind>Y</in1_cntr_ind>
<in1_cntr_no>KLFU 9061610 </in1_cntr_no>
<in1_dir_ind>N</in1_dir_ind>
<in1_rej_reason> </in1_rej_reason>
<in1_act_wt>05380</in1_act_wt>
<in1_act_wt_class>L</in1_act_wt_class>
<in1_out_act_wt>11330</in1_out_act_wt>
<in1_out_dt>200501162349</in1_out_dt>
<in1_survey>AD </in1_survey>
<in1_tt_blk> </in1_tt_blk>
<in1_cnrs_ind> </in1_cnrs_ind>
<in1_cnrs_no> </in1_cnrs_no>
<in1_eir_in_no>163128347</in1_eir_in_no>
<in1_yd_assgn>PC080102030301</in1_yd_assgn>
<in1_faded_cntr_ind>N</in1_faded_cntr_ind>
<in1_pos_ind> </in1_pos_ind>
<in2_cntr_ind> </in2_cntr_ind>
<in2_cntr_no> </in2_cntr_no>
<in2_dir_ind> </in2_dir_ind>
<in2_rej_reason> </in2_rej_reason>
<in2_act_wt> </in2_act_wt>
<in2_act_wt_class> </in2_act_wt_class>
<in2_out_act_wt> </in2_out_act_wt>
<in2_out_dt> </in2_out_dt>
<in2_survey> </in2_survey>
<in2_tt_blk> </in2_tt_blk>
<in2_cnrs_ind> </in2_cnrs_ind>
<in2_cnrs_no> </in2_cnrs_no>
<in2_eir_in_no> </in2_eir_in_no>
<in2_yd_assgn> </in2_yd_assgn>
<in2_faded_cntr_ind> </in2_faded_cntr_ind>
<in2_pos_ind> </in2_pos_ind>
</ARGC-ARGU>
]
00:00:47 weblogic server=t3://cng3wls8:80
00:00:47 Queue key, Queue Name=[GMS_Q,jms/citos/gms/HssQueue]
00:00:47 Sending Message :<pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<system_c>HPREGATE</system_c>
<trans_c>HSPG</trans_c>
<trans_dt>20050117000039</trans_dt>
<user_id_m></user_id_m>
<func_c>C</func_c>
<pm_n>XB 9327D</pm_n>
<chassis_type>99</chassis_type>
<chassis_ulw>7500 </chassis_ulw>
<pager_n>94931525</pager_n>
<pager_mode>M</pager_mode>
<source_c>P</source_c>
<export>
<purp_i>S</purp_i>
<cntr_n>HJCU 1181837 </cntr_n>
<tt_i>G</tt_i>
<new_cntr_n> </new_cntr_n>
<gway_to>T</gway_to>
<old_nmt_n> </old_nmt_n>
<kd_i>N</kd_i>
<gate_n>4</gate_n>
<mpt_i>N</mpt_i>
<hlr_creg_n>10049690000G</hlr_creg_n>
<tt_frm_dt>200501170000</tt_frm_dt>
<tt_to_dt>200501170359</tt_to_dt>
</export>
</pregate>
00:00:47 Msg send to Queue=[<pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<system_c>HPREGATE</system_c>
<trans_c>HSPG</trans_c>
<trans_dt>20050117000039</trans_dt>
<user_id_m></user_id_m>
<func_c>C</func_c>
<pm_n>XB 9327D</pm_n>
<chassis_type>99</chassis_type>
<chassis_ulw>7500 </chassis_ulw>
<pager_n>94931525</pager_n>
<pager_mode>M</pager_mode>
<source_c>P</source_c>
<export>
<purp_i>S</purp_i>
<cntr_n>HJCU 1181837 </cntr_n>
<tt_i>G</tt_i>
<new_cntr_n> </new_cntr_n>
<gway_to>T</gway_to>
<old_nmt_n> </old_nmt_n>
<kd_i>N</kd_i>
<gate_n>4</gate_n>
<mpt_i>N</mpt_i>
<hlr_creg_n>10049690000G</hlr_creg_n>
<tt_frm_dt>200501170000</tt_frm_dt>
<tt_to_dt>200501170359</tt_to_dt>
</export>
</pregate>
]
MY CODE
Code:
Private Sub btnSXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSXML.Click
OpenFileDialog3.ShowDialog()
'Show the pBarMain for the txtImport
pBarMain.Show()
Try
'To display the opened file directory in a read-only textbox to the user.
txtFileAndPath.Text = OpenFileDialog3.FileName()
'to clear the old dataset
ds.Clear()
'To perform reading of text file from the input done by user.
oRead = oFile.OpenText(txtFileAndPath.Text)
'To read the text file line by line.
While oRead.Peek <> -1
LineIn = oRead.ReadLine()
MessageBox.Show(LineIn)
End While
Life is a foreign language; all men mispronounce it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|