XML
  Home arrow XML arrow Page 6 - Designing Your Own Reporting Service: A We...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Designing Your Own Reporting Service: A Web Service to Convert XML to HTML Using XSL
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2005-12-19

    Table of Contents:
  • Designing Your Own Reporting Service: A Web Service to Convert XML to HTML Using XSL
  • Developing the XML Web Service
  • Developing the XML Web Service continued
  • Defining the XSLT
  • Executing and testing the XML Web Service
  • Understanding the web service
  • Improvements to the solution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Designing Your Own Reporting Service: A Web Service to Convert XML to HTML Using XSL - Understanding the web service


    (Page 6 of 7 )

    As you have successfully executed and tested the web service, let us go into the details of web service.  For the sake of clarity, I shall explain it to you part by part.

    Let us first consider the following code fragment:

                      // Create the XslTransform.
                      XslTransform xslt = new XslTransform();
     
                      XmlUrlResolver resolver = new XmlUrlResolver();
                      resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

    The above code fragment starts by creating an object “xslt” based on the class “XslTransform”.  The class “XslTransform” is mainly used to load XSL files and transform the XML accordingly. “XmlUrlResolver” is used to resolve external XML resources such as entities, document type definitions (DTDs) or schemas. It is also used to process include and import elements found in the Extensible StyleSheet Language (XSL) style sheets or XML Schema definition language (XSD) schemas.

    If the virtual directory does not require authentication, this property does not need to be set. Otherwise, the credentials of the user must be supplied. Different credentials can be associated with different URIs and added to a credential cache. The credentials can then be used to check authentication for different URIs, regardless of the original source of the XML.  In the above case, it simply uses the default credentials.

    Further proceeding we have the following two:

    // Load the stylesheet.
                      string sXSLLocation = GetXSLLocation();
                      xslt.Load( sXSLLocation );

    I think you can understand the above two very easily.  I simply get the XSL file location from the “web.config” file and load it to transform.  Next we have the following:

                      // Load the XML string.
                      XmlDataDocument xmlDoc = new XmlDataDocument();
                      xmlDoc.XmlResolver = resolver;
                      xmlDoc.LoadXml(sXMLSource);

    The above statements create a new “XmlDataDocument” object and load the XML string as “native XML” instead of “string based XML”.  This would help us to transform the XML very easily.

                      Stream stream = new MemoryStream();
                      xslt.Transform(xmlDoc, null, stream, resolver);
                      stream.Flush();
                      stream.Position = 0;
                      System.IO.StreamReader sr = new System.IO.StreamReader
    (stream);
                      return sr.ReadToEnd();

    The above mainly creates a “MemoryStream”, to hold the entire transformation.  The second statement transforms the XML to XSL based on the credentials and  writes it into the memory stream.  Finally, we use a “StreamReader” to read the entire information available in memory stream.

    More XML Articles
    More By Jagadish Chaterjee


       · Did you ever think of designing your own simple reporting service with technologies...
     

    XML ARTICLES

    - Using Regions with XSL Formatting Objects
    - Using XSL Formatting Objects
    - More Schematron Features
    - Schematron Patterns and Validation
    - Using Schematron
    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek