Xml文档需要在每个文件中获取相同的标记名称节点列表 [英] Xml document need to get the same tag name nodes list in each

查看:62
本文介绍了Xml文档需要在每个文件中获取相同的标记名称节点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我在下面显示XML文档



当我试图收集xmlnodes列表< attribute>节点我得到XML文档中存在的所有节点我只需要得到< attributes>节点作为基于< subject type =>的列表。内部文本可以帮助我。



我的代码收集attribut的节点列表:



I have XML document displayed below

When i am try to gather the xmlnodes list of <attribute> nodes i am getting all the nodes existed in the XML doc i need only to get the <attributes> Nodes as a list based on <subject type=""> inner text could any one help me.

My Code to gathers the node list of attribut :

XmlNodeList elemList = xdoc.DocumentElement.GetElementsByTagName("Attribute");







<eLinkResult>
<LinkSet>
<DbFrom>pubmed</DbFrom>
<IdUrlList>
<IdUrlSet>
<Id>20888710</Id>
<ObjUrl>
<Url>
http://linkinghub.elsevier.com/retrieve/pii/S0360-3016(10)00875-8
</Url>
<IconUrl LNG="EN">
//www.ncbi.nlm.nih.gov/corehtml/query/egifs/http:--linkinghub.elsevier.com-ihub-images-PubMedLink.gif
</IconUrl>
<SubjectType>publishers/providers</SubjectType>
<Category>Full Text Sources</Category>
<Attribute>full-text online</Attribute>
<Attribute>publisher of information in url</Attribute>
<Attribute>subscription/membership/fee required</Attribute>
<Provider>
<Name>Elsevier Science</Name>
<NameAbbr>ES</NameAbbr>
<Id>3048</Id>
<Url LNG="EN">http://www.elsevier.com/</Url>
</Provider>
</ObjUrl>
<ObjUrl>
<Url>
https://www.clinicalkey.com/content/playBy/pii?v=S0360-3016(10)00875-8
</Url>
<IconUrl LNG="EN">
//www.ncbi.nlm.nih.gov/corehtml/query/egifs/http:--dgb32t5jlo8kf.cloudfront.net-images-clinicalkey_linkout.png
</IconUrl>
<SubjectType>aggregators</SubjectType>
<Category>Full Text Sources</Category>
<Attribute>full-text online</Attribute>
<Attribute>subscription/membership/fee required</Attribute>
<Provider>
<Name>Clinical Key</Name>
<NameAbbr>clinicalk</NameAbbr>
<Id>8412</Id>
<Url LNG="EN">http://www.clinicalkey.com</Url>
</Provider>
</ObjUrl>









在此XML中,我想基于上面的Sibiling节点SsubjectType收集所有Attribute节点,并在列表中创建此Attribute节点。请帮助我







提前进行..提升..





IN this XML i would like to gather all the Attribute nodes based on the above Sibiling node SsubjectType and make this Attribute nodes in a list. pls help me



Thnaks in Advance..

推荐答案

您好Ravi,

您可以通过以下方式使用Linq获取元素。



示例XML文件

Hi Ravi,
You can fetch the elements by using Linq by following way.

Sample XML File
<family>
	<member>
		Abhishek Shukla
	</member>
	<member>
		Prateek Shukla
	</member>
	<member>
		Saurabh Shukla
	</member>
	<member>
		Sachin Shukla
	</member>
	<member>
		Vibhor Tiwari
	</member>
	<member>
		Tanmaya Dixit
	</member>
</family>





Linq代码





Linq Code

XDocument doc =   XDocument.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Family.xml"));

var temp = from node in doc.Descendants("Member")
where node.Value.Trim().Equals("Abhishek Shukla",StringComparison.OrdinalIgnoreCase)
select node;





别忘了添加命名空间System.XMl.Linq



希望这会有所帮助!



Don't forget to Add namespace System.XMl.Linq

Hope this helps!


看一下使用XPath的其他解决方案( http://www.w3schools.com/xpath/ [ ^ ])这里给出:如何使用gi获取xml数据ven关键字 [ ^ ]和这里:在XML中查找特定单词 [ ^ ]。
Take a look at some other solutions using XPath (http://www.w3schools.com/xpath/[^]) given here: how can i get the xml data by using given keyword[^] and here: Find Specific Word in XML[^].


这篇关于Xml文档需要在每个文件中获取相同的标记名称节点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆