根据XML中的一个属性值获取对应的另一个属性值

/// <summary>
/// 根据职务名字获取文书名字(领导批文时获取收件文书)
/// </summary>
/// <param name="str_sql"></param>
/// <returns></returns>
public string GetGtitles(string gtitls)
{
StringBuilder str_sqls = new StringBuilder();
str_sqls.Append("select sValueXml.value('(Wenshus/Wenshu[./Title=\"" + gtitls + "\"]/Name)[1]','varchar(max)') ");
str_sqls.Append(" FROM [OA_Base].[dbo].[OAWenShus] where sField = 'Wenshus' ");
object ds = SqlDbHelper.ExcuteScalar(SqlDbHelper.connectionStringLocalTransaction, CommandType.Text, str_sqls.ToString());
return ds != null ? ds.ToString() : "";
}

XML结构如下:

<Wenshus>
<Wenshu>
<Title>gGSWS</Title>
<Name>aaa,</Name>
<Description>公司文书</Description>
</Wenshu>
<Wenshu>
<Title>gZongHeWenShu</Title>
<Name>bbb</Name>
<Description>综合部文书</Description>
</Wenshu>
<Wenshu>
<Title>gSHWenShu</Title>
<Name>ccc</Name>
<Description>售后部文书</Description>
</Wenshu>
<Wenshu>
<Title>gKFWenShu</Title>
<Name>ddd</Name>
<Description>开发部文书</Description>
</Wenshu>
<Wenshu>
<Title>gCGWenShu</Title>
<Name>eee</Name>
<Description>采购部文书</Description>
</Wenshu>
<Wenshu>
<Title>gSCWenShu</Title>
<Name>fff</Name>
<Description>市场部文书</Description>
</Wenshu>
</Wenshus>

猜你喜欢

转载自www.cnblogs.com/cxy-sj/p/9016006.html