Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
398
The System.Xml.XmlWriter Class
Supported Versions
.NET Framework 1.0, 1.1, 1.2
Public Members
Bold members are covered in the sample code.
Public Properties
Public Methods
WriteState
Close
XmlLang
Equals
XmlSpace
Flush
GetHashCode
GetType
LookupPrefix
ToString
WriteAttributes
WriteAttributeString
WriteBase64
WriteBinHex
WriteCData
WriteCharEntity
WriteChars
WriteComment
WriteDocType
WriteElementString
WriteEndAttribute
WriteEndDocument
WriteEndElement
WriteEntityRef
WriteFullEndElement
WriteName
WriteNmToken
WriteNode
WriteProcessingInstruction
WriteQualifiedName
WriteRaw
WriteStartAttribute
WriteStartDocument
WriteStartElement
WriteString
WriteSurrogateCharEntity
WriteWhitespace
Overview
XmlWriter is an abstract class that is implemented using
the XmlTextWriter class. It provides the bulk of the members used by the XmlTextWriter
class, and establishes an important part of the System.Xml library.
Example (VB.NET): How
to pass an XmlTextWriter object to an XmlWriter declared parameter.
The following is a variation of the XmlTextWriter example.
Here we create an XmlTextWriter object in one subroutine (Button1_Click), and
then pass it to another routine (GetTheWriter) where it is received into the objXmlWriter
parameter that is typed as an XmlWriter object. The XMLWriter object is then
used to output the XML document content, using the WriteStartElement,
WriteString, and WriteEndElement methods. An XmlTextReader is subsequently used
to read in the document contents, which are then displayed with the
XmlDocument.OuterXml property.
Private Sub Button1_Click(...)
Dim objXmlTextWriter As System.Xml.XmlTextWriter
objXmlTextWriter = New
XmlTextWriter("c:\newtest.xml", Nothing)
GetTheWriter(objXmlTextWriter)
End Sub
Sub GetTheWriter(ByVal objXmlWriter As System.Xml.XmlWriter)
Dim objXmlDocument As System.Xml.XmlDocument
Dim objXmlTextReader As System.Xml.XmlTextReader
objXmlWriter.WriteStartElement("sampleElement")
objXmlWriter.WriteString("new value")
objXmlWriter.WriteEndElement()
objXmlWriter.Close()
objXmlTextReader = New
XmlTextReader("c:\newtest.xml")