I have a rather simple question. I'm trying to get information out of an XML file, and now I need to get the that's inside another
This is my XML code:
<author>
<name>Random_name1 (Random Name)</name>
<uri>http://thisisanrandomurl.com</uri>
</author>
I can get the info with this code:
Name = item.Element(ns + "author").Value,
But this gives me: "Random_name1 (R开发者_如何学Candom Name) http://thisisanrandomurl.com"
I only want the info inside the tags. Any ideas?
Thanks a lot, - Niels
Are you using LINQ to XML? Try:
Name = item.Element(ns + "author").Element(ns + "name").Value;
to get the data inside the 'name' element. You can use Elements
if there is more than one, and then use LINQ statements to select the one you want.
using System.Xml;
After then please write this code
XmlDocument myxml = new XmlDocument();
myxml.Load("D:/sample.xml");//Load you xml file from you disk what you want to load
string element_1 = myxml.GetElementsByTagName("name")[0].InnerText;
string element_2 = myxml.GetElementsByTagName("uri")[0].InnerText;
Please try this it will be useful to you...
精彩评论