successor of msxsl.exe?

流过昼夜 提交于 2019-12-22 04:17:12

问题


We intend to migrate our framework from msxml4 to msxml6. We where using msxsl.exe as yet. It seems to support only MSXML versions up to 4.0, as command line msxsl.exe -u version 6.0 tells me. Is there a successor of msxsl.exe? Any alternative command line processor?


回答1:


There are a number of ways you could replace the existing processor, it just depends on what level of functionality you require and whether you need MSXML specific functionality. For example there is xsltproc which is part of libxslt (can get some windows binaries from here for example). This page gives you a quick replacement in C# but both change the command line usage and might not implement the same MSXML extensions (xsltproc certainly doesn't).

If you are just interested in a simple command line processor which uses MSXML 6 then you could do worse than using a simple JScript application. Save the following code as xsltr.js and run as cscript msltr.js input.xml template.xsl output.txt:

var adTypeBinary = 1;
var adSaveCreateOverWrite = 2;
var adSaveCreateNotExist = 1;

try 
{
    var args = WScript.Arguments;

    if(args.length < 3)
    {
        WScript.Echo("Usage: xsltr.js file.xml file.xsl output.txt");
        WScript.Quit(1);
    }
    else
    {
        var xml = args(0);
        var xsl = args(1);
        var out = args(2);

        var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
        var xslDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");

        /* Create a binary IStream */
        var outDoc = new ActiveXObject("ADODB.Stream");
        outDoc.type = adTypeBinary;
        outDoc.open();

        if(xmlDoc.load(xml) == false)
        {
            throw new Error("Could not load XML document " + xmlDoc.parseError.reason);
        }

        if(xslDoc.load(xsl) == false)
        {
            throw new Error("Could not load XSL document " + xslDoc.parseError.reason);         
        }

        xmlDoc.transformNodeToObject(xslDoc, outDoc);
        outDoc.SaveToFile(out, adSaveCreateOverWrite);
    }
}
catch(e)
{
    WScript.Echo(e.message);
    WScript.Quit(1);
}

Still is there is a rationale you cannot use msxsl? Version 4.0 of MSXML has never been a standard installation so you would have always had to instal it manually (though I think it came with Office at one point). Could you not deploy version 4 on the machines you need to do the processing on?



来源:https://stackoverflow.com/questions/2058247/successor-of-msxsl-exe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!