0% found this document useful (0 votes)
3 views

complete-reference-vb_net_72

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

complete-reference-vb_net_72

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Writing XML Files with XMLTextWriter

WriteEndElement Closes one element and pops the corresponding namespace scope
WriteEntityRef Writes out an entity reference as follows: & name
WriteFullEndElement Closes one element and pops the corresponding namespace scope
WriteName Writes out the specified name, ensuring it is a valid name according
to the W3C XML 1.0 recommendation
(www.w3.org/TR/1998/REC−xml−19980210#NTName)
WriteNmToken Writes out the specified name, ensuring it is a valid NmToken
according to the W3C XML 1.0 recommendation
(www.w3.org/TR/1998/REC−xml−19980210#NTName)
WriteNode When overridden in a derived class, copies everything from the
reader to the writer and moves the reader to the start of the next
sibling
WriteProcessingInstruction Writes out a processing instruction with a space between the name
and text as follows: <?name text?>
WriteQualifiedName Writes out the namespace−qualified name. This method looks up
the prefix that is in scope for the given namespace.
WriteRaw Writes raw markup manually
WriteStartAttribute Writes the start of an attribute
WriteStartDocument Writes the XML declaration with the version "1.0"
WriteStartElement Writes the specified start tag
WriteString Writes the given text content
WriteSurrogateCharEntity Generates and writes the surrogate character entity for the surrogate
character pair
WriteWhitespace Writes out the given white space
The preceding code produces the following output (noo and oyvey are Yiddish XML):

<Body xmlns:noo="urn:1">
<noo:oyvey />
<noo:oyvey />
</Body>

The writer promotes the namespace declaration to the root element to avoid having it duplicated on the two
child elements. The child elements pick up the prefix from the namespace declaration. XmlTextWriter also
allows you to override the current namespace declaration. In the following example, the namespace URI "foo"
is overridden by "bar" to produce the XML element <q:node xmlns:q="bar"/>.

xmlRyter.WriteStartElement("q", "node", "foo")


xmlRyter.WriteAttributeString("xmlns", "q", Nothing, "bar")

The Write methods can take a prefix as an argument to let you specify which prefix to use. Also, if there are
multiple namespace declarations mapping different prefixes to the same namespace URI, XmlTextWriter
walks the stack of namespace declarations backward and picks the closest one. When the
WriteAttributeString call does not specify a prefix, the writer uses the last prefix pushed onto the namespace
stack.

If namespace conflicts occur, XmlTextWriter resolves them by generating alternate prefixes. For example, if
an attribute and element have the same prefix but different namespaces, XmlTextWriter generates an
alternate prefix for the attribute. The generated prefixes are named n{i}, where i is a number beginning at 1.

556

You might also like