从根节点获取属性值 [英] Get attribute value from a root node
本文介绍了从根节点获取属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我的xml文件的rootnode为Base,我的属性Name可用在根节点本身。我需要找出位于我的根节点中的属性值。我该怎么办,请尽快帮助我。供您参考,我特此为您提供样品。
< Baseclass ID =5Name =Raj>
< nextclass>
< / Baseclass>
解决方案
试试这个
XDocument xDoc = XDocument.Load( xml的路径);
var TagIds = xDoc.Descendants()
.Elements()
.Where(e = >
e.HasAttributes&&
e.Name.LocalName.Equals( 基类)&&
e.Attribute( ID)!= null )
。选择(e = > e.Attribute( ID)。值);
希望这有助于
Dim tempPath As String = FolderBrowserDialog1.SelectedPath& \& ListBox1.Items(x).ToString
Dim xSid =来自xattr In xDoc.Descendants(Baseclass)_
选择att = xattr.Attribute(Name)。值
sSID = xSid.ElementAt(0).ToString''SID值
Dear All,
I have my xml file with rootnode as "Base" and I have my attribute "Name" available in the root node itself. I need to find out my attribute value located in my root node. How could I proceed, please help me ASAP. For your reference I hereby providing you a sample.
<Baseclass ID="5" Name="Raj">
<nextclass>
</Baseclass>解决方案Try this
XDocument xDoc = XDocument.Load("path to xml"); var TagIds = xDoc.Descendants() .Elements() .Where(e => e.HasAttributes && e.Name.LocalName.Equals("Baseclass") && e.Attribute("ID") != null) .Select(e => e.Attribute("ID").Value);
Hope this helps
Dim tempPath As String = FolderBrowserDialog1.SelectedPath & "\" & ListBox1.Items(x).ToString
Dim xSid = From xattr In xDoc.Descendants("Baseclass") _
Select att = xattr.Attribute("Name").Value
sSID = xSid.ElementAt(0).ToString ''SID value
这篇关于从根节点获取属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文