我有以下xml:
<sample intentref="BIZ_hello" count="1">hey</sample>
<sample intentref="business_status" count="1">status of my order</sample>
<sample intentref="business_status" count="1">order for my number<annotation conceptref="o_number">12343</annotation>
我正在嘗試建立一個這樣的串列:
| 意圖 | 樣本 | 數數 | 注解 |
|---|---|---|---|
| BIZ_你好 | 嘿 | 1 | 沒有任何 |
| 業務狀態 | 我的訂單狀態 | 1 | 沒有任何 |
| 業務狀態 | 訂購我的號碼 | 1 | "<annotation conceptref=o_number>12343</annotation>" |
我一直在獲取“帶注釋的文本”部分。到目前為止,我的代碼適用于“intent”、“sample”和“count”......我正在嘗試獲取那個可選的 '' tag 。
XmlDocument xdoc = new XmlDocument();
xdoc.Load(fileName);
XmlNodeList nodes = xdoc.SelectNodes("project/samples/sample");
foreach (XmlNode xn in nodes)
{
ParseList tempList = new ParseList();
tempList.intentName = xn.Attributes["intentref"]?.Value ?? "Unassigned";
tempList.sampleSentence = xn.FirstChild.Value;
tempList.countSamples = xn.Attributes["count"].Value;
tempList.annotatedText = ???
}
uj5u.com熱心網友回復:
您可以使用以下
tempList.annotatedText = xn["annotation"]?.OuterXml ?? "NONE";
?處理節點不存在的情況。OuterXml將整個子節點作為文本回傳。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/493453.html
