0% found this document useful (0 votes)
16 views1 page

Complete-Reference-Vb Net 70

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Complete-Reference-Vb Net 70

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Writing XML Files with XMLTextWriter

• Document nodes can have the following child node types: XmlDeclaration, Element (maximum of
one), ProcessingInstruction, Comment, and DocumentType. Document nodes cannot appear as the
child of any node types.
• DocumentFragment nodes associate a node or subtree with a document without actually being
contained within the document. A DocumentFragment node can have the following child node
types: Element, ProcessingInstruction, Comment, Text, CDATA, and EntityReference.
DocumentFragment nodes cannot appear as the child of any node types.
• DocumentType nodes can have the following child node types: Notation and Entity. They can
appear as the child of the Document node.
• Element nodes can have the following child node types: Element, Text, Comment,
ProcessingInstruction, CDATA, and EntityReference. The Element can be the child of the
Document, DocumentFragment, EntityReference, and Element nodes.
• Entity nodes can have child nodes that represent the expanded entity (for example, Text and
EntityReference nodes). The Entity can appear as the child of the DocumentType node.
• EntityReference nodes can have the following child node types: Element, ProcessingInstruction,
Comment, Text, CDATA, and EntityReference. An EntityReference node can appear as the child
of the Attribute, DocumentFragment, Element, and EntityReference nodes.
• Notation nodes cannot have any child nodes. A Notation node can appear as the child of the
DocumentType node.
• ProcessingInstruction nodes cannot have any child nodes. Such a node can appear as the child of the
Document, DocumentFragment, Element, and EntityReference nodes.
• Text nodes cannot have any child nodes. The Text node can appear as the child node of the
Attribute, DocumentFragment, Element, and EntityReference nodes.
• XmlDeclaration nodes must be the first node in the document. This node cannot have children. It is a
child of the Document node. It can have attributes that provide version and encoding information.

Using the XmlTextReader is no different to using the earlier reader and writer classes discussed, so we don't
need any elaborate examples here to show how it works. The same goes for the XmlTextWriter class coming
up.

Writing XML Files with XMLTextWriter

The XMLTextWriter represents a writer that provides a fast, noncached, forward−only way of generating
streams or files containing XML data that conforms to the W3C Extensible Markup Language (XML) 1.0 and
the namespaces in XML recommendations.

The XmlTextWriter maintains a namespace stack corresponding to all the namespaces defined in the current
element stack. Using XmlTextWriter you can declare namespaces manually. Table 15−33 lists the pertinent
members of XmlTextWriter.

The following example writes data to represent a data set:

Public Sub rytzXml(ByVal target As String)


Dim xmlRyter As XmlTextWriter = New XmlTextWriter(target, _
System.Text.Encoding.ASCII)
xmlRyter.WriteStartElement("Body")
xmlRyter.WriteAttributeString("xmlns", "noo", Nothing, "urn:1")
xmlRyter.WriteStartElement("oyvey", "urn:1")
xmlRyter.WriteEndElement()
xmlRyter.WriteStartElement("oyvey", "urn:1")
xmlRyter.WriteEndElement()
xmlRyter.WriteEndElement()

554

You might also like