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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}}reader.Name,GetNodeAttributes(reader));break;case XmlNodeType.EndElement:buf = Str<strong>in</strong>g.Format("{0}",new Str<strong>in</strong>g(' ', 2*reader.Depth),reader.Name);break;case XmlNodeType.Text:buf = Str<strong>in</strong>g.Format("{0}{1}",new Str<strong>in</strong>g(' ', 2*reader.Depth),reader.Value);break;}OutputList.Items.Add(buf);The f<strong>in</strong>al text is <strong>in</strong>dented us<strong>in</strong>g a padd<strong>in</strong>g str<strong>in</strong>g whose size depends on the reader'sDepth property. Node names and values are returned by the Name and Valueproperties. For element nodes, attributes are read us<strong>in</strong>g a piece of code that weexam<strong>in</strong>ed <strong>in</strong> detail <strong>in</strong> Chapter 2:str<strong>in</strong>g GetNodeAttributes(XmlReader reader){if (!reader.HasAttributes)return "";str<strong>in</strong>g buf = "";while(reader.MoveToNextAttribute())buf += Str<strong>in</strong>g.Format("{0}=\"{1}\" ", reader.Name,reader.Value);}reader.MoveToElement();return buf;Output FormatsAn XSLT style sheet can declare the output <strong>for</strong>mat of the serialized text us<strong>in</strong>g the statement. This statement features several attributes, the most importantof which is method. The method attribute can be set with any of the follow<strong>in</strong>g keywords:xml, html, or text. By default, the output <strong>for</strong>mat is <strong>XML</strong> unless the root tag of the resultsdocument equals . In this case, the output is <strong>in</strong> HTML.Differences between <strong>XML</strong> and HTML are m<strong>in</strong>imal. If the output <strong>for</strong>mat is HTML, the<strong>XML</strong> well-<strong>for</strong>medness is sacrificed <strong>in</strong> the name of a greater programmer-friendl<strong>in</strong>ess.This means that, <strong>for</strong> example, empty tags will not have an end tag. In addition to263

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

Saved successfully!

Ooh no, something went wrong!