Hi Michael,
ein Beispiel aus der Referenz:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/
frlrfsystemxmlxmltextwriterclasswritestartdocumenttopic.htm
using System;
using System.IO;
using System.Xml;
public class Sample
{
private const string filename = "sampledata.xml";
public static void Main()
{
XmlTextWriter writer = null;
writer = new XmlTextWriter (filename, null);
//Use indenting for readability
writer.Formatting = Formatting.Indented;
//Write the XML delcaration
writer.WriteStartDocument();
//Write the ProcessingInstruction node
String PItext="type='text/xsl' href='book.xsl'";
writer.WriteProcessingInstruction("xml-stylesheet", PItext);
//Write the DocumentType node
writer.WriteDocType("book", null , null, "<!ENTITY h 'hardcover'>");
//Write a Comment node
writer.WriteComment("sample XML");
//Write an element (this one is the root)
writer.WriteStartElement("book");
//Write the genre attribute
writer.WriteAttributeString("genre", "novel");
//Write the ISBN attribute
writer.WriteAttributeString("ISBN", "1-8630-014");
//Write the title
writer.WriteElementString("title", "The Handmaid's Tale");
//Write the style element
writer.WriteStartElement("style");
writer.WriteEntityRef("h");
writer.WriteEndElement();
//Write the price
writer.WriteElementString("price", "19.95");
//Write CDATA
writer.WriteCData("Prices 15% off!!");
//Write the close tag for the root element
writer.WriteEndElement();
writer.WriteEndDocument();
//Write the XML to file and close the writer
writer.Flush();
writer.Close();
//Load the file into an XmlDocument to ensure well formed XML
XmlDocument doc = new XmlDocument();
//Preserve white space for readability
doc.PreserveWhitespace = true;
//Load the file
doc.Load(filename);
//Display the XML content to the console
Console.Write(doc.InnerXml);
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:bounce-aspdedotnet-954403@;aspfriends.com]On Behalf Of Mahler
Michael
Sent: Freitag, 08. November 2002 16:50
To: aspDEdotnet
Subject: [aspdedotnet] AW: RE: <?xml version="1.0" encoding="utf-8" ?>
in XML-Datei
Oops
kompletter Fehler:
System.InvalidOperationException: Beim Generieren des XML-Dokuments ist ein
Fehler aufgetreten. ---> System.ArgumentException: WriteStartDocument hat
die XML-Deklaration geschrieben.
Gru�
Michael
-----Urspr�ngliche Nachricht-----
Von: Manfred [mailto:News@;grube40.com]
Gesendet: Freitag, 8. November 2002 16:39
An: aspDEdotnet
Betreff: [aspdedotnet] RE: <?xml version="1.0" encoding="utf-8" ?> in
XML-Datei
Hi,
//Write the XML delcaration
xwriter.WriteStartDocument();
mfg Manfred
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:bounce-aspdedotnet-954403@;aspfriends.com]On Behalf Of Mahler Michael
Sent: Freitag, 08. November 2002 15:52
To: aspDEdotnet
Subject: [aspdedotnet] <?xml version="1.0" encoding="utf-8" ?> in XML-Datei
Hallo Liste,
stehe gerade vor einem Problem. Ich schreibe mit:
XmlTextWriter xwriter = new XmlTextWriter(strFileNameTemp,
System.Text.Encoding.UTF8);
xwriter.Formatting = Formatting.Indented;
xwriter.WriteStartElement("TeilnehmerID");
xwriter.WriteString(row["TeilnehmerID"].ToString());
xwriter.WriteEndElement();
....
xwriter.Flush();
xwriter.Close();
ein XML-File auf die Platte.
Nur fehlt dieser date das f�hrende " <?xml version="1.0" encoding="utf-8"
?>".
Hat jemand eine Idee, wie ich dies in die Datei bekomme???
Gru�
Michael Mahler
| [aspdedotnet] als [EMAIL PROTECTED] subscribed
| http://www.dotnetgerman.com/archiv/aspdedotnet/ = Listenarchiv Sie
| k�nnen sich unter folgender URL an- und abmelden:
| http://www.dotnetgerman.com/listen/aspDEdotnet.asp
| [aspdedotnet] als [EMAIL PROTECTED] subscribed
| http://www.dotnetgerman.com/archiv/aspdedotnet/ = Listenarchiv Sie
| k�nnen sich unter folgender URL an- und abmelden:
| http://www.dotnetgerman.com/listen/aspDEdotnet.asp
| [aspdedotnet] als [EMAIL PROTECTED] subscribed
| http://www.dotnetgerman.com/archiv/aspdedotnet/ = Listenarchiv
| Sie k�nnen sich unter folgender URL an- und abmelden:
| http://www.dotnetgerman.com/listen/aspDEdotnet.asp
| [aspdedotnet] als [email protected] subscribed
| http://www.dotnetgerman.com/archiv/aspdedotnet/ = Listenarchiv
| Sie k�nnen sich unter folgender URL an- und abmelden:
| http://www.dotnetgerman.com/listen/aspDEdotnet.asp