Conversione File Txt Xml Format
Stylus Studio provides several easy-to-use document wizards that allow you to quickly convert text files to XML. Create XML from text and EDI, create XML. CSV to XML Converter. This online tool allows you to convert a CSV file into a XML file. To make use of this converter, define a valid XML template using placeholders in the format ##POSITION## to substitute the value of the.
I try to convert text file to xml file using following code. But i get error in line 12. Could any one correct it and give me the correct answer. Nacho libre completa.
![File File](https://s3.amazonaws.com/marstranslation.aws.bucket/default/0001/10/aeac48d3cc080a27c365b85e2ecb1e31ae8c7e68.jpg)
Thanks
This is the Error
System.IndexOutOfRangeException was unhandled Message='Index was outside the bounds of the array.' Source='txtxml' StackTrace: at txtxml.Form1.button1_Click(Object sender, EventArgs e) in C:Documents and SettingsCrusadersMy DocumentsVisual Studio 2005ProjectstxtxmltxtxmlForm1.cs:line 31 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at txtxml.Program.Main() in C:Documents and SettingsCrusadersMy DocumentsVisual Studio 2005ProjectstxtxmltxtxmlProgram.cs:line 17 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
Come Aprire File Txt
![Conversione Conversione](https://www.e-time.it/wp-content/uploads/2016/03/300X300.jpg)
2 Answers
The code assumes that there exist at least four lines of text in the file.Are you sure this is the case?
I would suggest you write your code to first assert that the lines
array actually contains as many lines as you expect. It's entirely possible that the file does not - or that the line breaks are non-standard and therefore not recognized by ReadAllLines()
.
As a general rule, when parsing or splitting the contents of a file that you expect to have a certain format, you should write your code in a way that asserts your expectations. Otherwise, it can become quite difficult to diagnose what occurred when things go wrong.
Another place in your code you may want to re-examine, are lines like:
Here, again, you assume that the line has a certain structure, and then you access the second index in the result using the indexing operator []
- which could also be a potential source of the error.
@LBushkin raises one of the main problems with the code.
The second problem is that it assumes that each line contains atleast one '~'(you keep accessing .split(ca,2)[1]) , which does not seem to be the case in the sample txt file you posted.I suggest replacing all code of the form :