Im trying to extract data from the xml file
<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>
i have written the code
var res= doc.Element("year");
MessageBox.Show(""+res);
the xml file is loaded but im getting empty value on the messagebox how can i get the value from each node
year
是movie
元素的 属性 :
var year = (int)doc.Root.Element("movie").Attribute("year");
year
不是元素,而是attribute
,请尝试以下操作:
doc.Descendants("movie").First().Attribute("year").Value;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.