I made this before reading the updates and seeing you got an answer. Leaving it here just in case.
internal class Program
{
private static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("C:/xmlExample.xml");
XmlNode firstChild = doc.DocumentElement.FirstChild;
List<string> returningStrList = new List<string>();
GetStringList(doc.DocumentElement.ParentNode, returningStrList);
Console.WriteLine();
}
private static void GetStringList(XmlNode node, List<string> strList)
{
if (node.HasChildNodes)
foreach (XmlNode childNode in node.ChildNodes)
GetStringList(childNode, strList);
if (!string.IsNullOrEmpty(node.Value))
strList.AddRange(node.Value.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
}
}
XML structure:
<?xml version='1.0'?>
<example xmlns="urn:example-schema">
<myNode>
<data a="1000" b="20">
100 20000
</data>
<data a="12512" b="25">
200 1000
</data>
<data>
<subData k="aaaa">
subDataText 20
</subData>
400 kakaaka
</data>
</myNode>
</example>
你的XML結構不可見... – Tcanarchy
我已經編輯了你的文章,以便顯示XML,但是請在發佈時多加註意預覽 - 應該很明顯,該文章在其原始格式中沒有意義。另外,使用空格而不是製表符。 –