15.01.2013 Views

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

To validate an XmlDocument already in memory, add the schema(s) to the<br />

XmlDocument’s Schemas collection and then call the document’s Validate method,<br />

passing in a ValidationEventHandler to process the errors.<br />

XSLT<br />

XSLT stands for Extensible Stylesheet Language Transformations. It is an XML language<br />

that describes how to transform one XML language into another. The quintessential<br />

example of such a transformation is transforming an XML document (that<br />

typically describes data) into an XHTML document (that describes a formatted<br />

document).<br />

Consider the following XML file:<br />

<br />

Jim<br />

Bo<br />

<br />

The following XSLT file describes such a transformation:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The output is as follows:<br />

<br />

Jim<br />

Bo<br />

<br />

The System.Xml.Xsl.XslCompiledTransform transform class efficiently performs<br />

XLST transforms. It renders XmlTransform obsolete. XmlTransform works very simply:<br />

XslCompiledTransform transform = new XslCompiledTransform();<br />

transform.Load ("test.xslt");<br />

transform.Transform ("input.xml", "output.xml");<br />

Generally, it’s more useful to use the overload of Transform that accepts an<br />

XmlWriter rather than an output file, so you can control the formatting.<br />

474 | Chapter 11: Other XML Technologies

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

Saved successfully!

Ooh no, something went wrong!