读取 xml 并在控制器中查找?
我有一个示例 xml,
<Lookup>
<Controller Name="Activity1" >
<action Name="Editactivity1" appgroup="Something" productcode="SomethingElse"/>
</Controller>
<Controller Name="Activity2">
<action Name="Editactivity2" appgroup="Something1" productcode="SomethingElse2"/>
</Controller>
</Lookup>
控制器名称和操作名称存储在变量中。
var cntName;
var actName;
根据这些值,我必须查找此 Xml 并获取相应的 appgroup
和 productcode
值。
注意:cntName
的示例值为 Activity1
或 Activity2
或 ActivityN
。actName
的示例值为 EditActivity1
或 EditActivity2
或 EditActivityN
。
因此,根据这些值,我必须查找 xml,希望我清楚我的问题陈述。
我正在使用传统的 xmldatadocument 读取 xml,如何将其更改为 LINQ?示例如下。
XmlDocument xmlDocAppMod = new XmlDocument();
strFileName = System.Configuration.ConfigurationManager.AppSettings["AppModOptListPath"].ToString();
strFileLocation = System.Web.HttpContext.Current.Server.MapPath("~/" + strFileName);
xmlDocAppMod.Load(strFileLocation);
谢谢, 阿达什
I have a sample xml
<Lookup>
<Controller Name="Activity1" >
<action Name="Editactivity1" appgroup="Something" productcode="SomethingElse"/>
</Controller>
<Controller Name="Activity2">
<action Name="Editactivity2" appgroup="Something1" productcode="SomethingElse2"/>
</Controller>
</Lookup>
I have the controller name and action name stored in variables.
var cntName;
var actName;
Based on these values I have to look up this Xml and fetch the corresponding appgroup
and productcode
values.
Note: example values for cntName
would be Activity1
or Activity2
or ActivityN
.
Example values for actName
would be EditActivity1
or EditActivity2
or EditActivityN
.
So based on these values i have to look up the xml, Hope I am clear with my problem statement.
I am reading my xml using traditional xmldatadocument, how do i change it to LINQ? Sample below.
XmlDocument xmlDocAppMod = new XmlDocument();
strFileName = System.Configuration.ConfigurationManager.AppSettings["AppModOptListPath"].ToString();
strFileLocation = System.Web.HttpContext.Current.Server.MapPath("~/" + strFileName);
xmlDocAppMod.Load(strFileLocation);
Thanks,
Adarsh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您有多种选择:
从磁盘加载文档并创建 xPath 表达式来评估它:
另一个选项可能是使用 XDocument:
更新:
当然,您也可以将 xPath 与 Linq-to-XML 结合使用:
Basically, you have several options:
Load the document from disk and create an xPath expression to evaluate it:
Another option could be to use XDocument:
UPDATE:
Of course, you could use xPath with Linq-to-XML as well: