0
我從XDocument獲得輸出的方式有點麻煩,我希望它成爲一個.CSV文件。我想知道有人能幫助我嗎?從XDocument輸出到VB.NET中的.CSV文件
首先,這裏的XML:
<Main>
<Node1>
<Node1a>1</Node1a>
<Node1b>2</Node1b>
</Node1>
<Node2>
<Node2a>Three</Node2a>
<Node2b>Four</Node2b>
</Node2>
</Main>
我能夠將這個XML文檔轉換成字符串(即:下文稱爲sString),並把它傳遞到我的VB.NET功能。我目前有...
Dim doc As XDocument = XDocument.Parse(sString)
Dim myOutput As New StringBuilder(1000)
For Each node As XElement In doc.Descendants("Main")
For Each innerNode As XElement In node.Elements()
myOutput.AppendFormat("{0},", innerNode.Attribute("Node1a").Value)
myOutput.AppendFormat("{0},", "!")
myOutput.AppendFormat("{0},", innerNode.Attribute("Node1b").Value)
myOutput.AppendFormat("{0},", "!")
myOutput.AppendFormat("{0},", innerNode.Attribute("Node2a").Value)
myOutput.AppendFormat("{0},", "!")
myOutput.AppendFormat("{0},", innerNode.Attribute("Node2b").Value)
Next
myOutput.AppendLine()
Next
Dim finalCSVstring as string
finalCSVstring = myOutput.ToString()
這工作「有點」...但我想我得到了在節點的內部循環和寫出這些值搞砸了。
我想什麼是最終輸出的樣子:
1|2|Three|Four
,其中「|」分離各種值。