XmlTextWriter.WriteDocType(String, String, String, String) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
A DOCTYPE deklarációt a megadott névvel és opcionális attribútumokkal írja.
public:
override void WriteDocType(System::String ^ name, System::String ^ pubid, System::String ^ sysid, System::String ^ subset);
public override void WriteDocType(string name, string pubid, string sysid, string subset);
override this.WriteDocType : string * string * string * string -> unit
Public Overrides Sub WriteDocType (name As String, pubid As String, sysid As String, subset As String)
Paraméterek
- name
- String
A DOCTYPE neve. Ennek nem üresnek kell lennie.
- pubid
- String
Ha nem null, akkor a NYILVÁNOS "pubid" "sysid" szöveget is írja, ahol pubid a sysid függvény a megadott argumentumok értékével cserélődik le.
- sysid
- String
Ha pubid null értékű, és sysid nem null értékű, akkor a RENDSZER "sysid" értéket ír, ahol sysid az argumentum értéke lesz lecserélve.
- subset
- String
Ha nem null, akkor a [részhalmaz] szöveget írja, ahol a részhalmaz helyébe ennek az argumentumnak az értéke kerül.
Kivételek
Ezt a metódust a prologon kívül (a gyökérelem után) hívták meg.
name
null vagy String.Empty
-vagy-
az érték name érvénytelen XML-értéket eredményez.
Példák
Az alábbi példa egy könyvnek megfelelő XML-fájlt ír.
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 a root element.
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);
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Private Shared filename As String = "sampledata.xml"
Public Shared Sub Main()
Dim writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(filename, Nothing)
'Use indenting for readability.
writer.Formatting = Formatting.Indented
'Write the XML delcaration.
writer.WriteStartDocument()
'Write the ProcessingInstruction node.
Dim PItext As String = "type='text/xsl' href='book.xsl'"
writer.WriteProcessingInstruction("xml-stylesheet", PItext)
'Write the DocumentType node.
writer.WriteDocType("book", Nothing, Nothing, "<!ENTITY h 'hardcover'>")
'Write a Comment node.
writer.WriteComment("sample XML")
'Write a root element.
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.
Dim doc As 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)
End Sub
End Class
Megjegyzések
Note
Javasoljuk, hogy a XmlWriter metódus és a XmlWriter.Create osztály használatával hozzon létre XmlWriterSettings példányokat az új funkciók előnyeinek kihasználásához.
Ez a metódus nem ellenőrzi az érvénytelen karaktereket a ( sysid vagysubset) fájlbanpubid. Azt sem ellenőrzi, hogy a belső részhalmaz jól formázott-e.
Important
A XmlTextWriter rendszer nem ellenőrzi a metódusnak WriteDocType átadott adatokat. Nem szabad tetszőleges adatokat átadni ehhez a metódushoz.