【发布时间】:2016-12-30 01:18:17
【问题描述】:
我有一个平面文件,数据存储在 XML 行中。我正在使用脚本组件作为源解析 XML 行,如下所示。它工作正常,直到在特定行中,我们看不到其中一列。
例如:在源文件的第 12 行,它只有 Col1 和 Col2,没有 Col3。我需要修改下面的 C# 代码,以便当它在一行中找不到列时,它需要返回为 NULL。
public override void CreateNewOutputRows()
{
string filepath = @"c:\test\test\xmldata.txt";
string fileContent = new StreamReader(filepath).ReadToEnd();
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root>"+ fileContent+"</root>");
XmlNodeList xnl = doc.GetElementsByTagName("TICKET_EXTRACT");
foreach (XmlNode xn in xnl) {
Output0Buffer.AddRow();
Output0Buffer.col1 = xn["col1"].InnerText;
Output0Buffer.col2 = xn["col2"].InnerText;
Output0Buffer.col3 = xn["col3"].InnerText;
}
【问题讨论】: