0
我有IEnumerable<XElement> theTestCaseNodes
它具有以下一種XElements閱讀的IEnumerable <XElement>每個節點使用的XMLReader
<testcase>
<Main>
<test_step type ="action">
<Name>Goto</Name>
<description>xxxxxxxxx</description>
</test_step>
<test_step type ="check">
<Name>Click</Name>
<description>xxxxxxxxx</description>
</test_step>
</Main>
</testcase>
<testcase>
<Main>
<test_step type ="action">
<Name>Goto</Name>
<description>xxxxxxxxx</description>
</test_step>
<test_step type ="check">
<Name>Type</Name>
<description>xxxxxxxxx</description>
</test_step>
</Main>
</testcase>
基本上這是我的測試用例的,我想在一個順序來執行它們。 所以,現在我想使用XMLReader讀取IEnumerable中的每個節點。
請幫助如何着手!
我明白我需要使用「使用」,但不知道如何繼續。
public void ExecuteTestcase(IEnumerable<XElement> theTestCaseNodes)
{
using (XmlReader aNodeReader = XmlReader.ReadSubtree()) {
}
}
你可以寫你的XML到一個字符串,創建一個'StringReader'並將它傳遞給'XmlReader'。注意你必須在'using'中'創建'一個閱讀器,然後你可以調用像'ReadSubtree'這樣的實例方法。 – juharr
_你爲什麼要使用XmlReader?這用於將文本轉換爲DOM,但您已經有DOM級別的元素。 –
@HenkHolterman,請讓我知道更多關於此。我是XML的新手。我想在這裏使用XMLReader,因爲我想按順序排列。有2種步驟,「type = Action」和「type = check」,我想按順序閱讀它們。 – Diana