Click here to Skip to main content
15,851,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

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 :
C#
XmlNodeList elemList = xdoc.DocumentElement.GetElementsByTagName("Attribute");


XML
<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>




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..
Posted
Updated 6-Sep-13 2:42am
v7
Comments
_Asif_ 6-Sep-13 5:04am    
The sample you provided does not seem like XML. Please share the xml

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

Sample XML File
XML
<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 Code

C#
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;


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

Hope this helps!
 
Share this answer
 
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[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900