1
我是用C#查詢XML文件的新手。任何幫助,將不勝感激。在此先感謝..用LINQ XML查詢屬性值
我有這樣的XML文件:
<Point>
<Statement>
<Type />
<FullCondtion />
<ExpressionList />
</Statement>
<TestList>
<Test>
<Inputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="2" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="3" />
</Inputs>
<Outputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="0" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="0" />
</Outputs>
</Test>
<Test>
<Inputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="2" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="3" />
</Inputs>
<Outputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="0" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="0" />
</Outputs>
</Test>
</TestList>
<TestList>
<Test>
<Inputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="2" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="3" />
</Inputs>
<Outputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="0" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="0" />
</Outputs>
</Test>
<Test>
<Inputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="2" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="3" />
</Inputs>
<Outputs>
<Variable Name="u1_count" Value="0" />
<Variable Name="u1_flag" Value="0" />
<Variable Name="ON" Value="1" />
<Variable Name="OFF" Value="0" />
<Variable Name="u1_ch" Value="0" />
<Variable Name="u1_index" Value="0" />
</Outputs>
</Test>
</TestList>
</Point>
</Pattern>
</CodeAnalyzerResults>
我需要寫的輸入和輸出他們的價值觀變量在這樣的表:
輸入
u1_count 0 0 0 0
u1_flag 2 2 2 2
...
u1_index 3 3 3 3
和同樣是爲輸出做..我如何獲得的輸入和輸出值的每個變量和他們排成一排寫?
我讀這篇文章:http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/reading-xml-file-through-linq-a-few-tips/但我還是不能想辦法做到這一點..
感謝。但是,當我嘗試在我的代碼中使用它時,出現了兩個錯誤:參數2:無法從'System.Linq.IGrouping'轉換爲'string []'和'string.Join的最佳重載方法匹配字符串,字符串[])'有一些無效的參數。爲什麼?順便說一句,我會寫這些使用foreach循環的excel文件..預先感謝.. –
jaqui
2013-05-07 03:56:26
我能夠使用代碼通過添加'.ToArray',所以它成爲'讓價值= string.Join(「」, grp.ToArray())',但然後它'輸入'返回「枚舉沒有結果」..我做錯了什麼? – jaqui 2013-05-07 06:16:20
對不起,我錯過了一些東西,當導航到「輸入」時,我們必須下到「可變」元素。我編輯了答案,並且還添加了關於缺少'.ToArray'的修復。這次我測試了一下:-P – polkduran 2013-05-07 08:24:44