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.

stream. Some work<strong>in</strong>g memory is freed, the writer is not closed, and the operation cancont<strong>in</strong>ue.For example, let's assume that you use a file as the output stream. At some po<strong>in</strong>t, whilegenerat<strong>in</strong>g the <strong>XML</strong> content, you call Flush. As a result, the file (exist<strong>in</strong>g or alreadycreated by the time Flush is called) is partially populated. However, it can't be accessedby other processes because the file is locked by your process. The <strong>XML</strong> file will beunlocked and made available to other processes only when the writer is closed—anaction that, <strong>in</strong> turn, closes the stream and releases any underly<strong>in</strong>g resources.Table 4-4 summarizes the key methods of the XmlWriter class <strong>for</strong> writ<strong>in</strong>g specific <strong>XML</strong>elements such as attributes, entities, and nodes.Table 4-4: Writ<strong>in</strong>g Methods of the XmlWriter ClassMethodDescriptionWriteAttributeStr<strong>in</strong>gWrites an attribute with the specified value.The method adds start and end quotationmarks.WriteCData Writes a CDATA block conta<strong>in</strong><strong>in</strong>g thespecified text. The method adds start() blocks <strong>for</strong> theelement.WriteCharEntityWrites the specified Unicode character <strong>in</strong>hexadecimal character entity reference <strong>for</strong>mat.For example, the & (ampersand) character iswritten as &#x26;.WriteComment Writes a comment. The method adds start () blocks <strong>for</strong> the element.WriteDocTypeWrites the DOCTYPE declaration with thespecified name and optional attributes.WriteElementStr<strong>in</strong>gWrites an element node with the specifiedcontents. It can produce the follow<strong>in</strong>g outputwith a s<strong>in</strong>gle call: Rome, wherecity is the name of the element and Rome isthe contents to write.WriteEndAttribute Closes a previous call made toWriteStartAttribute.WriteEndDocumentCloses any open elements or attributes andreturns the writer to its <strong>in</strong>itial state (Start).WriteEndElementCloses the <strong>in</strong>nermost open element us<strong>in</strong>g theshort end tag (/>) where appropriate. Thenamespace scope moves one level up.WriteEntityRefWrites an entity reference with the specifiedname. Takes care of the lead<strong>in</strong>g & and thetrail<strong>in</strong>g semicolon (;).WriteFullEndElementCloses one element by us<strong>in</strong>g a full end tag (<strong>for</strong>example, ). This method is similarto WriteEndElement, but it always closes the<strong>in</strong>nermost element us<strong>in</strong>g a full end tag. Just aswith WriteEndElement, the namespace scopeis moved one level up.WriteNameWrites the specified name, ensur<strong>in</strong>g that it is a116

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

Saved successfully!

Ooh no, something went wrong!