UriFormatException未处理

时间:2015-04-09 19:06:09

标签: c# xml xslt

我从Web服务返回XML文档,我使用xsl schema将其转换为另一个XML文档。我收到了一个错误 'UriFormatException was unhandled. Invalid URI: The Uri string is too long.'但是如果我将SampleReportXML保存在临时文件夹中并阅读它,我就能获得所需的XML文档。任何帮助,将不胜感激。感谢。

       StringBuilder sb = new StringBuilder();
       XmlDocument doc = new XmlDocument();
       string inputXML =     @"C:\TEMP\SampleReport.xml";  
       string transformXSL = @"C:\TEMP\TransformSchema.xsl";   

       XslCompiledTransform xslt = new XslCompiledTransform();
       StringWriter writer = new StringWriter();
       xslt.Load(transformXSL);

        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = false;
        XmlWriter swriter = XmlWriter.Create(sb, settings);
        xslt.Transform(inputXML, null, swriter);
        sb.Append(writer.ToString());
        writer.Close();
        sb.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
        TextReader textReader = new StringReader(sb.ToString());
        doc.Load(textReader);
        return doc;


       XmlDocument SampleReportXML = new XmlDocument();
       SampleReportXML = WS.getReport(100);  //passing the parameter value to get the report XML doc from Web service
       string inputXML = SampleReportXML.InnerXml.ToString();
       string transformXSL = @"C:\TEMP\TransformSchema.xsl";


       XslCompiledTransform xslt = new XslCompiledTransform();
       StringWriter writer = new StringWriter();
       xslt.Load(transformXSL);

        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = false;
        XmlWriter swriter = XmlWriter.Create(sb, settings);
        xslt.Transform(inputXML, null, swriter); //getting error here
        sb.Append(writer.ToString());
        writer.Close();
        sb.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
        TextReader textReader = new StringReader(sb.ToString());
        doc.Load(textReader);
        return doc;

1 个答案:

答案 0 :(得分:1)

我认为你只想将SampleReportXML作为第一个参数传递给transform方法。目前,您正在将文档序列化为字符串,然后将字符串传递给期望Uri的方法。