SSRS导出报告到XML并删除<report>元素

时间:2015-09-24 22:45:20

标签: xml reporting-services export-to-xml

我正在尝试在SSRS中设置一个报告,订阅将一些数据导出为XML文件,以便将其导入另一个应用程序。然而,报告元素导致整个事情失败。

我的输出是:

<?xml version="1.0" encoding="utf-8" ?> 
<Report xsi:schemaLocation="BO http://reportserver?%2FBO.BILLING%20BacklogTest&rs%3AFormat=XML&rc%3ASchema=True" Name="BO" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="BO">
    <ForecastGroups>
        <ForecastGroup>
        <Code>BO.BILLING</Code> 
            <ActualOutstandingTasks>
            <TimeStamp>2015-09-25T00:00:00</TimeStamp> 
                <ArrivalPeriods>
                    <ArrivalPeriod>
                    <StopTime>2015-09-25T00:00:00</StopTime> 
                    <StartTime>2015-09-24T00:00:00</StartTime> 
                    <Tasks>2074</Tasks> 
                    </ArrivalPeriod>
                </ArrivalPeriods>
            </ActualOutstandingTasks>
        </ForecastGroup>
    </ForecastGroups>
  </Report>

除非我手动删除报表元素,否则它不起作用。我需要输出:

<?xml version="1.0" encoding="utf-8"?>
<ForecastGroups>
    <ForecastGroup>
        <Code>BO.BILLING</Code>
        <ActualOutstandingTasks>
            <TimeStamp>2015-09-25T00:00:00</TimeStamp>
            <ArrivalPeriods>
                <ArrivalPeriod>
                    <StopTime>2015-09-25T00:00:00</StopTime>
                    <StartTime>2015-09-24T00:00:00</StartTime>
                    <Tasks>2074</Tasks>
                </ArrivalPeriod>
            </ArrivalPeriods>
        </ActualOutstandingTasks>
    </ForecastGroup>
</ForecastGroups>

然后它运作正常。 SSRS中是否存在阻止报表元素呈现的方法?

谢谢, 格雷维尔

1 个答案:

答案 0 :(得分:0)

考虑使用XSLT,这是用于以任何方式,形状或形式转换XML内容的声明性模板语言!

当然,您需要一个XSLT处理器,它读取原始的.xml文件,使用下面的.xsl文件进行转换,并输出最终的.xml文件。实际上,所有现代编程语言都维护着XSLT库(Java,C#,Python,PHP,甚至是VBA,因为您可以使用日常的MS Access或MS Excel运行xsl transformation):

<?xml version='1.0' encoding='UTF-8'?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xsi:schemaLocation="BO http://reportserver?%2FBO.BILLING%20BacklogTest&amp;rs%3AFormat=XML&amp;rc%3ASchema=True"
       Name="BO" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bo="BO"> 
<xsl:output version="1.0" encoding="UTF-8"/>

<xsl:template match="bo:Report">
    <xsl:copy-of select="bo:ForecastGroups"/>
</xsl:template>

</xsl:transform>

输出:

<?xml version='1.0' encoding='UTF-8'?>
<ForecastGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="BO">
        <ForecastGroup>
        <Code>BO.BILLING</Code> 
            <ActualOutstandingTasks>
            <TimeStamp>2015-09-25T00:00:00</TimeStamp> 
                <ArrivalPeriods>
                    <ArrivalPeriod>
                    <StopTime>2015-09-25T00:00:00</StopTime> 
                    <StartTime>2015-09-24T00:00:00</StartTime> 
                    <Tasks>2074</Tasks> 
                    </ArrivalPeriod>
                </ArrivalPeriods>
            </ActualOutstandingTasks>
        </ForecastGroup>
    </ForecastGroups>

顺便提一下,原始XML的schemaLocation路径需要将&符号&转义为&amp;