开发者

How can I retrieve the text from a specific element of this XML?

I am trying to figure out Xmldocument for the first time. I cannot figure out how to pull a single element out of an xml file. I need to find a certain url in the xml document and determine if the user has access to that url and delete the xml related to that article if the user does not.

What I need to know if 开发者_JAVA技巧how to pull the inner text from <url></url> in the following xml

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

Sorry about the messy XML I am pulling directly from a the string where it is stored. I left off the rest of the xml as it is VERY long. How will I access the information I want?


using LINQ's XDocument:

from off the top of my head, syntax may be a little off

XDocument doc = XDocument.Parse(yourString);

string url = (from x in doc.Descendants("url") select x.Value).FirstOrDefault();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜