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.

XPath Expressions and XSLTIn the .<strong>NET</strong> Framework, XSLT and XPath expressions are fully supported but areimplemented <strong>in</strong> classes dist<strong>in</strong>ct from those that parse and write <strong>XML</strong> text. This is a keyfeature of the overall .<strong>NET</strong> <strong>XML</strong> API. Any functionality is provided through a smallhierarchy of objects, although each subtree connects and <strong>in</strong>teroperates well withothers. Figure 1-2 demonstrates the <strong>in</strong>terconnection between constituent APIs.Figure 1-2: The <strong>XML</strong>DOM API is built on top of readers and writers, but both XSLT andXPath expressions need to have a complete and <strong>XML</strong>DOM-based vision of the entire <strong>XML</strong>document to process it.<strong>XML</strong> readers and writers are the primitive elements of the .<strong>NET</strong> <strong>XML</strong> API. Whenever<strong>XML</strong> text must be parsed or written, all classes, directly or <strong>in</strong>directly, refer to them. Amore complex primitive element is the <strong>XML</strong>DOM tree. Trans<strong>for</strong>mations and advancedqueries must rely on the document <strong>in</strong> its entirety be<strong>in</strong>g held <strong>in</strong> memory and accessiblethrough a well-known <strong>in</strong>terface—the <strong>XML</strong>DOM.The XSLT ProcessorThe key class <strong>for</strong> XSLT is XslTrans<strong>for</strong>m. The class works as an XSLT processor andcomplies with version 1.0 of the XSLT recommendation. The class has two keymethods, Load and Trans<strong>for</strong>m, whose behavior is <strong>for</strong> the most part selfexplanatory.Once you acquire an <strong>in</strong>stance of the XslTrans<strong>for</strong>m class, you first load the source of anXSL document that conta<strong>in</strong>s the trans<strong>for</strong>mation rules. By call<strong>in</strong>g the Trans<strong>for</strong>m method,you actually per<strong>for</strong>m the conversion from native <strong>XML</strong> to the output <strong>for</strong>mat. Prior toapply<strong>in</strong>g the trans<strong>for</strong>mation, the underly<strong>in</strong>g <strong>XML</strong> document is loaded as a k<strong>in</strong>d of<strong>XML</strong>DOM tree. (The details of XSLT are covered <strong>in</strong> Chapter 7.)18

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

Saved successfully!

Ooh no, something went wrong!