[英]Extracting data from xml
我正在尝试从xml文件中提取数据
<root response="True">
<movie title="True Grit" year="1969" rated="N/A" released="11 Jun 1969" runtime="128 min" genre="Adventure, Western, Drama" director="Henry Hathaway" writer="Charles Portis (novel), Marguerite Roberts (screenplay)" actors="John Wayne, Glen Campbell, Kim Darby, Jeremy Slate" plot="A drunken, hard-nosed U.S. Marshal and a Texas Ranger help a stubborn young woman track down her father's murderer in Indian territory." language="English" country="USA" awards="Won 1 Oscar. Another 7 wins & 5 nominations." poster="http://ia.media-imdb.com/images/M/MV5BMTYwNTE3NDYzOV5BMl5BanBnXkFtZTcwNTU5MzY0MQ@@._V1_SX300.jpg" metascore="N/A" imdbRating="7.4" imdbVotes="26,487" imdbID="tt0065126" type="movie" tomatoMeter="90" tomatoImage="certified" tomatoRating="7.9" tomatoReviews="48" tomatoFresh="43" tomatoRotten="5" tomatoConsensus="N/A" tomatoUserMeter="83" tomatoUserRating="3.8" tomatoUserReviews="24,949" DVD="21 Mar 2000" BoxOffice="N/A" Production="Paramount Home Video" Website="N/A"/>
</root>
我已经写了代码
var res= doc.Element("year");
MessageBox.Show(""+res);
xml文件已加载,但是即时消息框上的值为空,我如何从每个节点获取值
year
是movie
元素的 属性 :
var year = (int)doc.Root.Element("movie").Attribute("year");
year
不是元素,而是attribute
,请尝试以下操作:
doc.Descendants("movie").First().Attribute("year").Value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.