XSLTO

One technique we (MSDN2) are considering using for mapping our Xml messages to our middle tier objects uses XPath statements in C#. The XPath statements are used to map sections of Xml to functions.

This is technique was prototyped by Tim Ewald during our last development cycle.

General Overview

This project is a prototype implementation of a technique for mapping xml sections to methods using xpath statements.

Input

The prototype expects the sample input file XMLFile1.xml. The file contains 3 elements:

<person>
  <name>Tim</name>
  <age>34</age>
</person>

Output

The prototype maps each element to a method and the element values to a method. Each method outputs the name or value to the console. The console output is:

person
name
Tim
age
34

Implementation Specifics

  1. Introduced an attribute MatchAttribute for tying xpath statements to methods.
  2. Introduced the Transform class. It is not intended to be used directly. It is meant to do the basic mechanics of matching xpath to methods, invoking methods and doing the general walking of the document.
  3. Introduced the MyTransform class. This class derives from Transform; it has methods mapped to specific expected input elements. For the sample input (XMLFile1.xml), it has 3 methods (Person, Name and Age). These map to the corresponding elements in the sample input file, outputting the name of the element to the console. It has one additional method which is mapped to the value of an element -- “text()”. This method outputs the value to the console.

Contact

This sample was provide by Kimberly Wolk.

Copyright

COPYRIGHT © 2005 MICROSOFT, CORP. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.