13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

What the XmlWriter Class Can't DoAlthough powerful and considerably feature-rich, an <strong>XML</strong> writer is not perfect; it stillleaves some marg<strong>in</strong> <strong>for</strong> errors. To be more precise, the XmlWriter class certa<strong>in</strong>lygenerates 100-percent well-<strong>for</strong>med code, but only if you pass on correct <strong>in</strong><strong>for</strong>mation. Inparticular, an <strong>XML</strong> writer does not check <strong>for</strong> <strong>in</strong>valid characters <strong>in</strong> element and attributenames. It also does not guarantee that any Unicode characters you use fit <strong>in</strong>to thecurrent encod<strong>in</strong>g schema. As a consequence, any characters outside the encod<strong>in</strong>gschema are not escaped <strong>in</strong>to character entities and might lead to <strong>in</strong>correct output.An <strong>XML</strong> writer also does not verify duplicate attributes; it simply dumps the text outwhen you call the appropriate method. Nor does an <strong>XML</strong> writer validate any identifiers(<strong>for</strong> example, the SYSTEM identifier) you specify when you create a DOCTYPE node.In addition, the XmlWriter class does not validate aga<strong>in</strong>st any schema or document typedef<strong>in</strong>ition (DTD). Creat<strong>in</strong>g a validat<strong>in</strong>g writer is not difficult, however; I'll give you sometips on how to build one <strong>in</strong> the section "<strong>XML</strong> Validat<strong>in</strong>g Writers," on page 168. By theway, an XmlValidat<strong>in</strong>gWriter class is just one of the extensions to the System.Xmlnamespace slated <strong>for</strong> the next version of the .<strong>NET</strong> Framework.Properties of the XmlWriter ClassTable 4-1 lists the properties that belong to the XmlWriter class.Table 4-1: Properties of the XmlWriter ClassPropertyWriteStateXmlLangXmlSpaceDescriptionRead-only property that gets the state of the writer. The statecan be any value taken from the WriteState enumeration anddescribes the element be<strong>in</strong>g written.Read-only property that returns the current xml:lang scope.You set the language of the document by writ<strong>in</strong>g an xml:langattribute to the output stream.Read-only property that <strong>in</strong>dicates the current xml:space scopethrough a value taken from the XmlSpace enumeration(Default, None, or Preserve).All of these properties are read-only and abstract—that is, they must be overridden <strong>in</strong>any derived class. The behavior described <strong>in</strong> Table 4-1 simply <strong>in</strong>dicates what theproperties have been designed <strong>for</strong> and does not necessarily reflect the actual behaviorof these properties <strong>in</strong> a custom implementation.In general, the XmlWriter class properties serve to track the state <strong>in</strong> which anothercomponent might have left the writer. Note that these properties belong to the current<strong>in</strong>stance of the writer object. If you are us<strong>in</strong>g the same writer to generate moredocuments on the same stream, these properties are not automatically reset when youstart a new document.<strong>XML</strong> Writer StatesTable 4-2 summarizes the allowable states <strong>for</strong> an <strong>XML</strong> writer. Values come from theWriteState enumeration type. Any <strong>XML</strong> writer is expected to properly and promptlyupdate its WriteState property as various <strong>in</strong>ternal operations take place.Table 4-2: States of an <strong>XML</strong> WriterStateAttributeDescriptionThe writer enters this state when an attribute is be<strong>in</strong>gwritten.114

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!