mission details:
Transform files in a simple text format into a file that defines the XML format.
Development language:
C # (console procedure)
Text file format:
Academic teaching plan, DeplomateachPlan non-qualified professional training program, SubjectCertificateTeachPlan
Files of XML formats after transition
XML Version = "1.0" encoding = "GB2312" Standalone = "YES"?>
<
Datasheet
>
<
Data
>
<
cnname
>
Academic teaching plan
CNNAME>
<
Enname
>
DeplomateachPlan
Enname>
<
Description
/>
<
Remark
/>
<
Short
/>
Data>
<
Data
>
<
cnname
>
Non-academic professional training teaching plan
CNNAME>
<
Enname
>
SubjectCertificateTeachPlan
Enname>
<
Description
/>
<
Remark
/>
<
Short
/>
Data>
The original code is as follows: USING SYSTEM;
Using system.io;
USING SYSTEM.XML;
Namespace TextFileToxml
{
///
/// This program is written in an example program of the SDK. ///
Class textFiletoxml
{
PUBLIC STATIC STRING FILE;
Public Static StreetReader Stream;
Public static xmltextwriter xwriter;
[Stathread]
Static void main (string [] args)
{
/ / The first parameter is the text file path and name that will be changed.
File = args [0];
// Create a new stream representing the file we are
// reading from.
Stream = new streamreader (file, system.text.encoding.getencoding ("GB2312"), TRUE);
// Create a new xmltextwriter. The name of the XML file to be created
Xwriter = New XmlTextWriter (Args [1], System.Text.Encoding.Getencoding ("GB2312"));
// write the beginning of the document incruute
// Document Declaration. Standalone Is True.
Xwriter.writestartDocument (TRUE);
// Write the beginning of the "data" element. This is
// the opening tag to our data
Xwriter.writestartElement ("Datasheet");
String input;
While (input = stream.readline ())! = null)
{
String [] strcontent = INPUT.SPLIT (','); if (strContent.length> = 2)
{
Xwriter.writestartElement ("DATA");
Xwriter.writeElementstring ("cnname", strcontent [0]);
Xwriter.writeElementString ("Enname", StrContent [1]);
Xwriter.WriteElementstring ("Description", "");
Xwriter.WriteElementstring ("Remark", ");
Xwriter.writeElementstring ("Short", "");
Xwriter.writeEndelement ();
}
}
// end the "data" element.
Xwriter.writeEndelement ();
// end the document
Xwriter.writeEnddocument ();
// flush the xml document to the underlying stream and
// Close The Underlying Stream. The Data Will NOT BE
// Written Out to the street () in // Written Out To the Stream Until Either
//Method is caled or the close () Method is Called.
Xwriter.close ();
}
}
}