SVG from VB

  • 17 years ago

    Hi
    I am trying to use VB to run a XSLT stylesheet against some XML data to populate a predefined SVG graph I have created.  
    The graph is basically a barchart from a Wrox book and uses a XSLT processer like SAXON engine, but a freind said you can do from within the VB code using -


    Msxml2.FreeThreadedDOMDocument.4.0


    Can anyone help with the process and objects needed.

  • 17 years ago

    Hi
    is it you just want to transform the xml from one format to the other?
    if yes, just reference MS XML 2.0 or  3.0 to your project.
    then do this

    Code:

    dim xml as domdocument
    dim xsl as domdocument
    xml.load yourfile.xml
    xsl.load yourfile.xsl
    xml.transformNode xsl

    hope it helps
    bernd

  • 17 years ago

    bernd
    thanks for your reply


    What I have is some xml data and xsl stylesheet that creates a SVG graph.  The xsl file contains all the <xsl:value-of select as well as the graph or chart instructions.  The xml data just includes a href to the stylesheet, but in the example, the only way to produce the SVG file is to use a XLST processor called SAXON, and at the command line you need to invoke the processor by typing saxon Data.xml Stylesheet.xsl Results.svg with hopefully displays the results.


    What i am wanting to do, is to do this using the MS XML 2.0 or  3.0 object.


    Thanks
    Cropa

  • 17 years ago

    Hi cropa
    you only need the domdocument object.
    -first load your data and stylesheet to seperate doms.
    -then use the documents transformNode method to get the result of the transformation as a string.
    -use the loadxml method to load that string to yet another dom.
    -save this dom using its save method


    Code:

    set xml =CreatObject("msxml2.domdocument")
    set xsl =CreatObject("msxml2.domdocument")
    set svg=CreatObject("msxml2.domdocument")


    xml.Load "c:/hall0/Data.xml"
    xsl.Load "c:/hall0/stylesheet.xsl"


    svg.loadXML xml.transformNode(xsl)


    svg.save "c:/hall0/Results.svg"




    this way it should work.
    bye
    bernd

  • 17 years ago

    Thanks bernd, this works great
    Heres my code for anyone else who gets stuck.



    Code:

    Dim xml As New DOMDocument30
    Dim xsl As New DOMDocument30
    Dim svg As New DOMDocument30


       Set xml = New DOMDocument30
       xml.Load ("c:\svg\VerticalBarvXSLT.xml")
       xsl.Load ("c:\svg\VerticalBarvXSLT.xsl")
       svg.loadXML xml.transformNode(xsl)
       svg.save "c:\svg\Results.svg"

  • 17 years ago

    Hi Cropa and brend,


    Thank you so much for your codes, it really useful for me.
    I just have one specific question.
    How can I use URL instead of using


    xml.Load ("c:\svg\VerticalBarvXSLT.xml")
    xsl.Load ("c:\svg\VerticalBarvXSLT.xsl")


    Using URL like this :


    xml.Load ("www.mydomain\svg\VerticalBarvXSLT.xml")
    xsl.Load ("www.mydomain\svg\VerticalBarvXSLT.xsl")


    is that possible


    Thanks again for your helping


    Reza

  • 17 years ago

    Hi
    for that purpose you will need
    the msxml2.xmlHttp object instead of domdocument.
    with xmlhttp you can do this:

    Code:
    Dim http As New MSXML2.XMLHTTP
    http.open "post", "http://www.domain.com/seite.xml", False, "user", "Password"
    http.send ""
    text1.Text=http.responseText

    http.response.Text will hold the seite1.xml as a string.
    you can now load that string into a domdocument using dom.loadxml...
    hth
    bye

  • 17 years ago

    Dear Brend,


    Thank you so much , it is work fine, thank you!!
    I just have other question , how can I save svg result to remote machine.
    I apperciate in advance for your help


    Reza

  • 17 years ago

    Hi,


    I am having input xmls (which are always greater than 100 MB) and i am using MSXSL processor and VB Script in it. Further i am getting 7 different outputs by running seven times msxsl command line utility.


    But if i run msxsl's command line utility i need to load same input file 7 times.


    Since load times is always taking plenty of time everytime, i thought of loading it once and running it over 7 different xsl i.e. stylesheet and get seven different outputs.


    My question here are
    1) Can i do like this  ?
    2) How do i pass parameter to xsl ?
    3) how do i load different xsl using same object ? (Attached a code here to do this but giving error)
    4) how do i save the output ?


    Current code:





    Private Sub Form_Load()
    Dim strParamVal As String
       Dim strParamName As String
       Dim myDoc As Object
       
       Dim xmlDoc As New FreeThreadedDOMDocument30
       Dim xslDoc As New FreeThreadedDOMDocument30
    '    Dim xslDoc1 As New FreeThreadedDOMDocument30 ' tried this but giving path not found error even if files is present there
       Dim template As New MSXML2.XSLTemplate30
       Dim processor As MSXML2.IXSLProcessor
       Dim result As New DOMDocument30
       
       
           'xslDoc.validateOnParse = True
           'xmlDoc.validateOnParse = True
    Debug.Print "Start time: " & Format(Now, "hh:mm:ss")


           xslDoc.Load "C:\First.xsl"
           Debug.Print "Time After loading stylesheet: " & Format(Now, "hh:mm:ss")
           
           xmlDoc.Load "C:\1.xml"
           Debug.Print "Time After loading inputFile: " & Format(Now, "hh:mm:ss")
           
           Set template.stylesheet = xslDoc
           Set processor = template.createProcessor
           processor.input = xmlDoc
           processor.Transform
           Debug.Print processor.output
           Debug.Print "Time After processing asset: " & Format(Now, "hh:mm:ss")
           Set xslDoc = Nothing ' is this all right ?
         


           xslDoc1.Load "C:\Second.xsl"
           Debug.Print "Time After loading basic stylesheet: " & Format(Now, "hh:mm:ss")
           Set template.stylesheet = xslDoc
           Set processor = template.createProcessor
           processor.input = xmlDoc
           processor.Transform
           Debug.Print processor.output
           Debug.Print "Time After processing basic: " & Format(Now, "hh:mm:ss")


    End Sub






    Thanks in the anticipation that i will get some hint to solve this problem.


    Regards,

  • 17 years ago

    Hi
    iv never used the xslprocessor class.so
    i dont know the transformation process is correct.
    as for that part:

    Code:

    Set xslDoc = Nothing ' is this all right ?

    i would use
    Code:

    Set xslDoc = Nothing ' is this all right ?
    set xslDoc = New FreeThreadedDOMDocument30

    but if u use this way you ve got to declare the xslDoc variable as follows.


    dim xslDoc as FreeThreadedDOMDocument30
    set xslDoc = New FreeThreadedDOMDocument30
    hth
    bye

  • 17 years ago

    Hi,


    Thanks for replying.


    I am doing that to load multiple xsl after loading one input xml.


    Because most of the time is consumed in loading only and my requirement is such to have 7 output from one inut file for which i have written 7 xsl files.


    Can you please show me how do i redirect the output using xslProcessor class to the file. Currently i am doing by taking its output to string object (does it have limitations) and then copying that string to the output file.


    Thanks once again
    Regards,
    Dipesh

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous