问题描述
我正在使用xml文件,并使用dataset.readxml函数读取该xml文件,在该函数中我获取了所有表明智的标签
但是现在我的问题是我想迭代forloop来检查第一个表/标记是否匹配,然后再次我想获取该表,然后再次迭代并匹配另一个值.
例如如果xml在表列表的第6行中包含标记名"component",我想获取该名称并再次进行迭代以获取其他信息.现在在组件中,我想用输入参数值检查类是否匹配,然后再进一步检查.
Hi,
I am using xml file and reading that xml file using dataset.readxml function where I am getting all table wise tag
but right now my problem is I want to iterate forloop to check first table/tag if that matched then again i want to get that table and again iterate and match the other value.
e.g. if xml contains tag name ''component'' at 6th row of table list I want to get that and again iterate for other information. Now in component i want to check class with my input parameter value if match then i want to go further like that.
for (int i = 0; i < CompXMLDataSet.Tables.Count; i++)
{
DataTable DT = CompXMLDataSet.Tables[i];
string TagName = DT.TableName.ToString();
//if (TagName == "COMPONENT")
if (TagName == "COMPONENT")
{
for (int j = 0; j < DT.Rows.Count; j++)
{
if (DT.Rows[j]["name"].ToString() == classname)
{
string Componentid = DT.Rows[j]["Component_id"].ToString();
for (int ii = 0; ii < CompXMLDataSet.Tables.Count; ii++)
{
DT = CompXMLDataSet.Tables[ii];
TagName = DT.TableName.ToString();
if (TagName == "VAR")
{
DataRow[] dtrow = DT.Select("Component_id=" + Componentid);
for (int k = 0; k < dtrow.Length; k++)
{
if (Convert.ToInt32(dtrow.ElementAt(k)["vid"]) == cid)
{
ParType = GetParType(dtrow.ElementAt(k)["type"].ToString());
return ParType;
}
}
}// if loop for TagName=="VAR"
}
}// if loop to check class name
} // For loop
} //if loop for TagName=="COMPONENT"
}
这里的cid和classname是我传递给此方法的参数,该参数将根据更改.
我想减少执行时间.
有什么简单的方法可以减少时间.我们可以为上面编写任何linq查询吗?
谢谢
sjs
here cid and classname are my parameter passed to this method which will change according.
I want to reduce the execution time.
Is there any easy way to reduce the time. can we write any linq query for above?
Thanks
sjs
推荐答案
from e in xmlDoc.Descendents("components")
where e.Elements("name") == somevalue
...
不完整,但是应该给您一个开始
Not complete but is should give you a start
这篇关于LINQ查询XML和数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!