我會實際存儲它稍有不同。 Concept是你創建一個「Process」複雜類型,然後在RelatedProcess中重用它,如果需要,你可以命名一個屬性。
<Job>
<Process>something.exe</Process>
<RelatedProcess>
<Process>
<Name>somethingelse.exe</Name>
</Process>
<Process>
<Name>OneMorething.exe
</Name>
</Process>
</RelatedProcess>
</Job>
這將允許更好的增長。例如,如果你決定要遞歸processeses即:
<Job>
<Process>
<Name>something.exe</Name>
<RelatedProcess>
<Process>
<Name>somethingelse.exe</Name>
<RelatedProcess>
<Process>
<Name>recursive.exe</Name>
</Process>
</RelatedProcess>
</Process>
<Process>
<Name>OneMorething.exe</Name>
</Process>
</RelatedProcess>
</Process>
</Job>
這裏是一個XDocument例子..我沒有表現出遞歸創作的過程,因爲我不知道,如果你想使用它。
string xml = "<Job>...xml here ";
XDocument doc = XDocument.Parse(xml);
var Processess = from process in doc.Elements("Job").Elements("Process")
select new
{
ProcessName = process.Element("Name"),
RelatedProcesses = (from rprocess in process.Elements("RelatedProcess").Elements("Process")
select new
{
ProcessName = rprocess.Element("Name")
}
).ToList()
};
讓我知道如果你有問題。
來源
2010-10-26 12:34:59
Nix
您得到了在解析XML一些很好的意見,但我們在黑暗中是那種爲要與文本內容做什麼。你想在*之前和之後提取子字符串? – LarsH 2010-10-26 13:51:47