本文整理匯總了C#中System.Xml.XmlTextWriter.WriteEndDocument方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTextWriter.WriteEndDocument方法的具體用法?C# XmlTextWriter.WriteEndDocument怎麽用?C# XmlTextWriter.WriteEndDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteEndDocument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
public static void Main()
{
using (XmlTextWriter writer = new XmlTextWriter(DirPath, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = ' ';
writer.Indentation = 2;
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
writer.WriteStartDocument();
writer.WriteStartElement("directories");
try
{
TraverseDirectory(desktopPath, writer);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Change the desktopPath.");
}
writer.WriteEndDocument();
}
Console.WriteLine("Xml document successfully created.");
}
示例2: WriteXMLDocument
private static void WriteXMLDocument(List<List<Review>> allResults)
{
string fileName = "../../reviews-search-results.xml";
Encoding encoding = Encoding.GetEncoding("UTF-8");
using (XmlTextWriter writer = new XmlTextWriter(fileName, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("search-results");
foreach (var results in allResults)
{
writer.WriteStartElement("result-set");
var orderedResult = (from e in results
orderby e.DateOfCreation
select e).ToList();
WriteBookInXML(orderedResult, writer);
writer.WriteEndElement();
}
writer.WriteEndDocument();
}
}
示例3: SaveRegister
private bool SaveRegister(string RegisterKey)
{
try
{
Encryption enc = new Encryption();
FileStream fs = new FileStream("reqlkd.dll", FileMode.Create);
XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8);
// Khởi động tài liệu.
w.WriteStartDocument();
w.WriteStartElement("QLCV");
// Ghi một product.
w.WriteStartElement("Register");
w.WriteAttributeString("GuiNumber", enc.EncryptData(sGuiID));
w.WriteAttributeString("Serialnumber", enc.EncryptData(sSerial));
w.WriteAttributeString("KeyRegister", enc.EncryptData(RegisterKey, sSerial + sGuiID));
w.WriteEndElement();
// Kết thúc tài liệu.
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
w.Close();
fs.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
示例4: Main
static void Main(string[] args)
{
string textFile = "../../PersonData.txt";
string xmlFile = "../../Person.xml";
using (XmlTextWriter xmlWriter = new XmlTextWriter(xmlFile, Encoding.GetEncoding("utf-8")))
{
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.IndentChar = '\t';
xmlWriter.Indentation = 1;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("person");
xmlWriter.WriteAttributeString("id", "1");
using (StreamReader fileReader = new StreamReader(textFile))
{
string name = fileReader.ReadLine();
xmlWriter.WriteElementString("name", name);
string address = fileReader.ReadLine();
xmlWriter.WriteElementString("address", address);
string phone = fileReader.ReadLine();
xmlWriter.WriteElementString("phone", phone);
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
}
}
示例5: CreateXml
public void CreateXml()
{
if ( ( m_SeasonList.Count > 0 ) )
{
const string fileName = "NFL.xml";
XmlTextWriter writer = new
XmlTextWriter(string.Format("{0}{1}", Utility.OutputDirectory() + "xml\\", fileName), null);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteComment( "Comments: NFL Season List" );
writer.WriteStartElement( "nfl" );
writer.WriteStartElement("season-list");
foreach ( NflSeason s in m_SeasonList )
{
WriteSeasonNode( writer, s );
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
RosterLib.Utility.Announce( fileName + " created" );
}
}
示例6: Create
public void Create( string path )
{
XmlTextWriter xml;
if( path == "" )
{
return;
}
m_fileName = path;
if( File.Exists( m_fileName ) == false )
{
xml = new XmlTextWriter( m_fileName, System.Text.Encoding.UTF8 );
xml.Formatting = System.Xml.Formatting.Indented;
xml.WriteStartDocument();
xml.WriteStartElement( "mdna" );
xml.WriteEndElement();
xml.WriteEndDocument();
xml.Close();
}
}
示例7: WriterXml
/// <summary>
/// 寫入配置參數數據
/// </summary>
/// <param name="Path"></param>
public void WriterXml(string Path)
{
try
{
// 創建XmlTextWriter類的實例對象
XmlTextWriter textWriter = new XmlTextWriter(Path, null);
textWriter.Formatting = Formatting.Indented;
// 開始寫過程,調用WriteStartDocument方法
textWriter.WriteStartDocument();
// 寫入說明
textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
textWriter.WriteComment("w3sky.xml in root dir");
//創建一個節點
textWriter.WriteStartElement("Administrator");
textWriter.WriteElementString("Name", "formble");
textWriter.WriteElementString("site", "w3sky.com");
textWriter.WriteEndElement();
// 寫文檔結束,調用WriteEndDocument方法
textWriter.WriteEndDocument();
// 關閉textWriter
textWriter.Close();
}
catch (System.Exception e)
{
Console.WriteLine(e.ToString());
}
}
示例8: Main
public static void Main()
{
using (XmlTextWriter writer = new XmlTextWriter("../../albums.xml", Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("albums");
using (XmlTextReader reader = new XmlTextReader("../../catalog.xml"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "name")
{
writer.WriteStartElement("album");
writer.WriteElementString("name", reader.ReadElementString());
}
if (reader.Name == "artist")
{
writer.WriteElementString("artist", reader.ReadElementString());
writer.WriteEndElement();
}
}
}
}
writer.WriteEndDocument();
}
}
示例9: Main
static void Main(string[] args)
{
using (XmlTextWriter writer = new XmlTextWriter(OutputPath, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
writer.WriteStartElement("albums");
using (XmlReader reader = XmlReader.Create(InputPath))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "name")
{
writer.WriteStartElement("album");
writer.WriteElementString("name", reader.ReadElementString());
}
else if (reader.Name == "artist")
{
writer.WriteElementString("artist", reader.ReadElementString());
writer.WriteEndElement();
}
}
}
}
writer.WriteEndDocument();
}
Console.WriteLine("Parsing is finished. Your document is ready.");
}
示例10: Dump2Xml
/// <summary>
/// Converts the memory hash table to XML
/// </summary>
public void Dump2Xml()
{
if ( ( TheHT.Count > 0 ) && IsDirty )
{
XmlTextWriter writer = new
XmlTextWriter( string.Format( "{0}", Filename ), null );
writer.WriteStartDocument();
writer.WriteComment( "Comments: " + Name );
writer.WriteStartElement( "media-list" );
IDictionaryEnumerator myEnumerator = TheHT.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
MediaItem m = (MediaItem) myEnumerator.Value;
WriteMediaNode( writer, m );
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
Utility.Announce( string.Format( "{0} created.", Filename ) );
}
else
Utility.Announce( string.Format( "No changes to {0}.", Filename ) );
}
示例11: SaveAsXml
public static void SaveAsXml(IEnumerable<Chapter> chapters, string path)
{
var writer = new XmlTextWriter(path, Encoding.GetEncoding("ISO-8859-1"));
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteDocType("Chapters", null, "matroskachapters.dtd", null);
writer.WriteStartElement("Chapters");
writer.WriteStartElement("EditionEntry");
foreach (var chapter in chapters.Where(chapter => chapter.Keep))
{
writer.WriteStartElement("ChapterAtom");
writer.WriteStartElement("ChapterTimeStart");
writer.WriteString(chapter.StartTimeXmlFormat); // 00:00:00.000
writer.WriteEndElement();
writer.WriteStartElement("ChapterDisplay");
writer.WriteStartElement("ChapterString");
writer.WriteString(chapter.Title); // Chapter 1
writer.WriteEndElement();
if (chapter.Language != null && chapter.Language != Language.Undetermined)
{
writer.WriteStartElement("ChapterLanguage");
writer.WriteString(chapter.Language.ISO_639_2); // eng
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
示例12: ImportXMLfile
static void ImportXMLfile(int popMember)
{
string filename = "";
filename = GlobalVar.jobName + GlobalVar.popIndex.ToString() + popMember.ToString();
XmlTextWriter xml = null;
xml = new XmlTextWriter(filename, null);
xml.WriteStartDocument();
xml.WriteStartElement("Features");
xml.WriteWhitespace("\n");
for (int i = 0; i < GlobalVar.featureCount; i++)
{
xml.WriteElementString("Index", i.ToString());
xml.WriteElementString("Value", GlobalVar.features[i].ToString());
xml.WriteWhitespace("\n ");
}
xml.WriteEndElement();
xml.WriteWhitespace("\n");
xml.WriteEndDocument();
//Write the XML to file and close the writer.
xml.Flush();
xml.Close();
}
示例13: TraverseDirectory
/// <summary>
/// The traverse directory.
/// </summary>
/// <param name="directory">
/// The directory.
/// </param>
public static void TraverseDirectory(string directory)
{
// Write a program to traverse given directory and write to a XML file its contents together with all subdirectories and files.
var dir = new DirectoryInfo(directory);
using (writer = new XmlTextWriter(xmlDirFilename, Encoding.UTF8))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("dirStructure");
foreach (var file in dir.GetFiles())
{
writer.WriteStartElement("file");
writer.WriteAttributeString("name", file.Name);
writer.WriteEndElement();
}
foreach (var subDir in dir.GetDirectories())
{
CreateSubdirectoryXml(subDir);
}
writer.WriteEndDocument();
}
}
示例14: Main
static void Main()
{
using (StreamReader reader = new StreamReader(filePath))
{
string line = reader.ReadLine();
if (line == null)
{
Console.WriteLine("The text file is empty");
return;
}
using (XmlTextWriter writer = new XmlTextWriter(xmlFilePath, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("People");
writer.WriteAttributeString("name", "People's List");
while (line != null)
{
WritePerson(line, writer);
line = reader.ReadLine();
}
writer.WriteEndDocument();
}
}
}
示例15: saveSettingsButton_Click
public void saveSettingsButton_Click(object sender, EventArgs e)
{
Form1 parent = (Form1)Application.OpenForms["Form1"];
FileStream fs = new FileStream("artsin_launcher.cfg", FileMode.Create);
XmlTextWriter writer = new XmlTextWriter(fs, Encoding.Unicode);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("ArtSinLauncherCfg");
writer.WriteAttributeString("version", "1.1");
writer.WriteStartElement("Memory");
writer.WriteAttributeString("minMemory", ((int)minMemNumericUpDown.Value).ToString());
writer.WriteAttributeString("maxMemory", ((int)maxMemNumericUpDown.Value).ToString());
writer.WriteEndElement();
writer.WriteStartElement("SaveSettings");
writer.WriteAttributeString("isTrue", saveSettingsCheckBox.Checked.ToString());
writer.WriteEndElement();
writer.WriteStartElement("Login");
writer.WriteAttributeString("value", parent.loginTextBox.Text);
writer.WriteEndElement();
writer.WriteStartElement("License");
writer.WriteAttributeString("isTrue", parent.licenseCheckBox.Checked.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
fs.Close();
}