2013-12-13 64 views
0

如何使用整個XML結構而不是第一個節點來獲取ReadXml來構建DataSet?如何使用整個XML結構而不僅僅是第一個節點來獲取ReadXml來構建DataSet?

我使用DataSet.ReadXml(MemoryStream)讀取SSRS XML蒸汽的結果。

出口SSRS到XML錯誤「命名的‘值’已經屬於數據表中的列:不能設置相同名稱的嵌套表名

我得到的錯誤監守一些子節點都空白atributes,和其他人基本上沒有,第一個Parent擁有所有空白子元素的子元素,第二個父元素有一些子元素具有這些屬性的值。當ReadXml構建數據集時,它使用第一個父元素的結構,然後在閱讀時炸彈在第二個父級中

我使用不同的日期範圍調用相同的SSRS報告使用較短的日期範圍,當數據較少並且出現錯誤時使用較長的da問題範圍不存在。的XML的結構不發生變化,除了諸如節點:

<TrendingChartGroup2 Label="Sep&#xA;&#xD;2013"> 
    <Value Y="0"/> 

變爲這樣的:

<TrendingChartGroup2 Label="Jun&#xA;&#xD;2013"> 
    <Value/> 

不DataSet.ReadXml(MemoryStream的)建立數據集結構基於斷第一XML節點它看到了嗎? 在加載數據集之前是否有讀取XML結構的方法,以便DataSet不是從它找到的前幾個節點創建的自動創建的?

下面是顯示已知良好和已知的不良xml節點和值的XML片段。

已知正確的:

<?xml version="1.0" encoding="utf-8"?> 
<Report xsi:schemaLocation="MyReport2 http://reportserver?%2FMyReport2&amp;rs 

%3AFormat=XML&amp;rc%3ASchema=True" Name="MyReport2" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="MyReport2"> 
    <Rehosp30DaysCurrDxChart1> 
     <Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_DxGroupName Label="Episode Of Care 

As Treatment DxGroupName"> 
      <TrendingChartGroup2_Collection> 
       <TrendingChartGroup2 Label="Oct&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Nov&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Dec&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jan&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Feb&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Mar&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Apr&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="May&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jun&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jul&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Aug&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Sep&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
      </TrendingChartGroup2_Collection> 
     </Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_DxGroupName> 
     <Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_Pneumonia Label="Episode Of 

Care As Treatment Pneumonia"> 
      <TrendingChartGroup2_Collection> 
       <TrendingChartGroup2 Label="Oct&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Nov&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Dec&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jan&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Feb&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Mar&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Apr&#xA;&#xD;2013"> 
        <Value Y="1"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="May&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jun&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jul&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Aug&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Sep&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
      </TrendingChartGroup2_Collection> 
     </Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_Pneumonia> 
    </Rehosp30DaysCurrDxChart1> 
</Report> 

已知的壞:

<?xml version="1.0" encoding="utf-8"?> 
<Report xsi:schemaLocation="MyReport2 http://reportserver?%2FMyReport2&amp;rs 

%3AFormat=XML&amp;rc%3ASchema=True" Name="MyReport2" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="MyReport2"> 
    <Rehosp30DaysCurrDxChart1> 
     <Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_DxGroupName Label="Episode Of Care 

As Treatment DxGroupName"> 
      <TrendingChartGroup2_Collection> 
       <TrendingChartGroup2 Label="Jul&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Aug&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Sep&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Oct&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Nov&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Dec&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jan&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Feb&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Mar&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Apr&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="May&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jun&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
      </TrendingChartGroup2_Collection> 
     </Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_DxGroupName> 
     <Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_Pneumonia Label="Episode Of 

Care As Treatment Pneumonia"> 
      <TrendingChartGroup2_Collection> 
       <TrendingChartGroup2 Label="Jul&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Aug&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Sep&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Oct&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Nov&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Dec&#xA;&#xD;2012"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jan&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Feb&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Mar&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Apr&#xA;&#xD;2013"> 
        <Value Y="1"/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="May&#xA;&#xD;2013"> 
        <Value/> 
       </TrendingChartGroup2> 
       <TrendingChartGroup2 Label="Jun&#xA;&#xD;2013"> 
        <Value Y="0"/> 
       </TrendingChartGroup2> 
      </TrendingChartGroup2_Collection> 
     </Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_Pneumonia> 
    </Rehosp30DaysCurrDxChart1> 
</Report> 

任何幫助,將不勝感激。我不明白DataSet.ReadXml(MemoryStream)如何構建數據集。

謝謝!

編輯:我應該添加我需要這在數據集中,因爲現有的代碼使用遍佈整個地方的數據集。有沒有辦法去XDocument修復這個問題的DataSet?

+0

我懷疑SSRS XML數據的結構是分層的,而XML格式的普通數據集是扁平結構。通過閱讀數據試圖完成什麼?我假設你正在改變它的其他目的?爲什麼不直接跳過SSRS過程並直接查詢數據庫? –

+0

我們正在對來自事務數據庫的「已知好」查詢進行SSRS報告輸出(xml)的自動測試。 SSRS報告針對立方體數據使用MDX查詢。我們將SSRS輸出與「已知好」查詢進行比較。 QA查詢和SSRS XML數據都會放入數據表中進行操作和比較。通常情況下,XML會很好,而不是隻有少量的數據。 :/ – BClaydon

回答

0

我不會在這種情況下使用DataSet.Readxml。重新考慮閱讀你的XML的方法可能是一個好主意。 .NET提供了許多方法來執行此操作。這裏有一些文章要審查。

你問題就變成了,如何單元測試SSRS輸出。此外,作爲單元測試人員,您是否想測試xml的SSRS結構或結構中提供的值?

測試結構

我裝的SSRS XML在Visual Studio中使用的XML菜單生成和XML Schema(XSD)文件。顯而易見,模式設計包含來自報表MDX查詢的元數據,因此如果要驗證所生成的xml結構是否正確,則可能需要創建一些模板文檔並替換某些元素名稱,然後使用一些.net xml結構驗證方法。見http://support.microsoft.com/kb/307379

<xs:element name="Rehosp30DaysCurrDxChart1"> 
     <xs:complexType> 
     <xs:sequence> 
      <xs:element name="Episode_x0020_Of_x0020_Care_x0020_From_x0020_Hospital_x0020_DxGroupName"> 
      <xs:complexType> 
       <xs:sequence> 
       <xs:element name="TrendingChartGroup2_Collection"> 
        <xs:complexType> 
        <xs:sequence> 
         <xs:element maxOccurs="unbounded" name="TrendingChartGroup2"> 
         <xs:complexType> 
          <xs:sequence> 
          <xs:element name="Value" /> 
          </xs:sequence> 
          <xs:attribute name="Label" type="xs:string" use="required" /> 
         </xs:complexType> 
         </xs:element> 
        </xs:sequence> 
        </xs:complexType> 
       </xs:element> 
       </xs:sequence> 
       <xs:attribute name="Label" type="xs:string" use="required" /> 
      </xs:complexType> 
      </xs:element> 

測試數據

文本格式的XML數據在單元測試可以做多種方式。您可以走xml dom或使用xPath來確認值。這可能會使你的單元測試有點複雜。

文本輸出的原始XML

最後,如果你有一組良好的XML結果,你可以只比較來自SSRS到你的「預期的XML結果」的原始XML文本作爲一個簡單的替代兩以上方法。雖然我沒有使用它,你可能想要檢出任何xml單元測試工具,如http://xmlunit.sourceforge.net/

+0

對您有幫助嗎? –

相關問題