XML獲取XML節點的值在C#
<table>
<row>
<field name="ID">22490</field>
<field name="post_date">2014-03-24 09:55:50</field>
<field name="post_title">Joe Bloggs</field>
<field name="post_status">Live</field>
<field name="post_modified">2017-07-31 15:33:46</field>
</row>
<row>
<field name="ID">29078</field>
<field name="post_date">2017-08-01 08:19:57</field>
<field name="post_title">Mary Poppins</field>
<field name="post_status">auto-draft</field>
<field name="post_modified">2017-08-01 08:19:57</field>
</row><table>
林通過上面的XML試圖循環,我怎麼可以從上面的POST_TITLE領域獲得的價值「李四」?
這是我到目前爲止有:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\\myxmlfile.xml");
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("row");
foreach (XmlNode node in nodeList)
{
string post_title = /// how can i get this
string post_status = /// how can i get this
}
我可以通過節點列表循環然而,我不能讓每個字段中的值。
「只是不能賦值給變量」 - 你是什麼意思?你可以發佈[mcve]嗎? (這顯然不是完整的XML文檔,否則它會有兩個根元素。)我也強烈建議使用LINQ to XML,但這是另一回事。 –