Transform XML with XSL in compact framework (c#)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sladan
    New Member
    • Mar 2007
    • 12

    #1

    Transform XML with XSL in compact framework (c#)

    I know compact framework doesn't support XslTranform, but is ther any way that you can work around this if you want to transform a XML-document with a XSL sheet?
  • sani723
    New Member
    • Feb 2007
    • 117

    #2
    check this http://www.xprogramming.com/xpmag/ac...xperiments.htm

    Comment

    • Sladan
      New Member
      • Mar 2007
      • 12

      #3
      Originally posted by sani723
      Thanks, but you cant use XslTransform in compact framework :-(

      Comment

      • dorinbogdan
        Recognized Expert Contributor
        • Feb 2007
        • 839

        #4
        You can use MSXML DOM object, by importing the type library or through Reflection.
        See these 2 C# examples.
        To apply the XSL template over XML use the transformNode() method of the DOM object.

        For reference, I give you a JavaScript example:
        [html]<PRE nd="52"><html>
        <body>

        <script type="text/javascript">

        // Load XML
        var xml = new ActiveXObject(" Microsoft.XMLDO M")
        xml.async = false
        xml.load("cdcat alog.xml")

        // Load XSL
        var xsl = new ActiveXObject(" Microsoft.XMLDO M")
        xsl.async = false
        xsl.load("cdcat alog.xsl")

        // Transform
        document.write( xml.transformNo de(xsl))

        </script>

        </body>
        </html>
        </PRE>[/html]

        You can use the version existing on your system:
        MSXML2.DOMDocum ent.3.0,
        MSXML2.DOMDocum ent.4.0 or
        Microsoft.XMLDO M

        If not sure what version you have, run Start/Run/regedit, and search for it.

        Comment

        • dorinbogdan
          Recognized Expert Contributor
          • Feb 2007
          • 839

          #5
          A simpler solution to use the XML DOM object:
          From Project/Add Reference/COM add a reference to Microsoft XML v4.0.
          Add this line in code:
          Code:
          using MSXML2;
          Then you can instantiate a DOM object, like:
          Code:
          MSXML2.DOMDocument40 doc = new DOMDocument40Class();
          When using the doc object you will see listed all its methods:
          doc.load, doc.loadXML, doc.transformNo de....

          I hope this helps.

          Comment

          • Sladan
            New Member
            • Mar 2007
            • 12

            #6
            Yes it did! Thanks a lot! I had almost given up. :-)

            Comment

            • dorinbogdan
              Recognized Expert Contributor
              • Feb 2007
              • 839

              #7
              Glad to hear that.
              You're always welcome.
              God bless you,
              Dorin.

              Comment

              • Sladan
                New Member
                • Mar 2007
                • 12

                #8
                It seems that I took out my victory a little to early. I tried to add the dll-file like you said.

                "From Project/Add Reference/COM add a reference to Microsoft XML v4.0."

                However I didn't have a section named COM. So i downloaded msxml4.dll and tried to add it, but i didn't work. So i downloaded msxml3.dll instead and it worked fine.

                Now I wrote

                Code:
                using MSXML2;
                and then

                Code:
                MSXML2.DOMDocument30 doc = new DOMDocument30Class();

                I get a COMException and the following description:

                COM object with CLSID '{F5078F32-C551-11D3-89B9-0000F81FE221}' cannot be created due to the following error: 0x80040154.

                Thanks in advance!

                Comment

                • dorinbogdan
                  Recognized Expert Contributor
                  • Feb 2007
                  • 839

                  #9
                  Did you register the dll?

                  If not, try to run "regsvr32 msxml3.dll" within Start/Run.
                  Or install the MSXML kit.

                  Comment

                  • Sladan
                    New Member
                    • Mar 2007
                    • 12

                    #10
                    Only getting errors, I guess it could be Vista messing it up. I'll just have to write a converter manually. Thanks anyway, really appreciate you taking an interest in my problem.

                    Comment

                    • dorinbogdan
                      Recognized Expert Contributor
                      • Feb 2007
                      • 839

                      #11
                      I'm sorry about that strange behavior.
                      However, keep the contact here.

                      Regarding the compact framework, try also to post any questions on .Net forum.

                      Thanks,
                      Dorin.

                      Comment

                      • koti9876
                        New Member
                        • Mar 2008
                        • 3

                        #12
                        I want convert the xml file to html file.I have xml file in \\abc.xml and xls file is in D:\abc.xsl can u tell the code to get abc.html after the fallowd line.

                        MSXML2.DOMDocum ent40 doc = new DOMDocument40Cl ass();

                        Regardds,
                        koti.

                        Originally posted by dorinbogdan
                        I'm sorry about that strange behavior.
                        However, keep the contact here.

                        Regarding the compact framework, try also to post any questions on .Net forum.

                        Thanks,
                        Dorin.

                        Comment

                        Working...