我试图第一次找出Xmldocument。我无法弄清楚如何从xml文件中提取单个元素。我需要在xml文档中找到某个url并确定用户是否有权访问该url并删除与该文章相关的xml(如果用户没有)。
如果从以下xml中的<url></url>
中提取内部文本,我需要知道
<?xml version="1.0" encoding="UTF-8"?>
<searchdoc><results hits="3226" time="0.33" query="test" suggest="test1" filter="" sort="relevance" sortdir="desc" start="1" end="10" currentpage="1" lastpage="323" startdate="0" enddate="0" xsl="Trane.xsl">
<result no="1"><url>c:\RECYCLER\S-1-5-21-3289705215-1832128825-2807327032-470872\Dc115
\test-files\test.ppt</url><col>3</col><lastmodified>25 Feb 2011 20:14:41
GMT</lastmodified><indexdate>11 Mar 2011 20:40:17 GMT</indexdate><size>75264</size>
<title><highlight>Test</highlight></title><alpha>Test</alpha><keywords
/><contenttype>PPT</contenttype><context>Nutch Parser <highlight>Test</highlight> My
initial <highlight>test</highlight> file for the PowerPoint parser of nutch Second
page <highlight>Test</highlight> Of PowerPoint Extraction Some Unicode I do not know
the content and I can not read it, just gathered from other ppt-files: áéíóú Stephan
Strittmatter</context><description>Nutch Parser <highlight>Test</highlight> My initial
<highlight>test</highlight> file for the PowerPoint parser of nutch ...</description>
<language>en</language><score>100</score></result>
很抱歉我直接从存储它的字符串中提取凌乱的XML。因为它很长,所以我放弃了xml的其余部分。我如何获取我想要的信息?
答案 0 :(得分:3)
使用LINQ的XDocument:
从我的头顶,语法可能有点偏离
XDocument doc = XDocument.Parse(yourString);
string url = (from x in doc.Descendants("url") select x.Value).FirstOrDefault();