这是响应(XML):
<?xml version="1.0" encoding="UTF-8"?>
<root response="True">
<movie
title="Taken 3"
year="2015"
rated="PG-13"
released="09 Jan 2015"
runtime="109 min"
genre="Action, Crime, Thriller"
director="Olivier Megaton"
writer="Luc Besson, Robert Mark Kamen"
actors="Liam Neeson, Maggie Grace, Famke Janssen, Forest Whitaker"
plot="Liam Neeson returns as ex-covert operative Bryan Mills, whose long awaited reconciliation with his ex-wife is tragically cut short when she is brutally murdered. Consumed with rage, and framed for the crime, he goes on the run to evade the relentless pursuit of the CIA, FBI and the police. For one last time, Mills must use his 'particular set of skills,' to track down the real killers, exact his unique brand of justice, and protect the only thing that matters to him now - his daughter."
language="English"
country="France"
awards="N/A"
poster="http://ia.media-imdb.com/images/M/MV5BNjM5MDU3NTY0M15BMl5BanBnXkFtZTgwOTk2ODU2MzE@._V1_SX300.jpg"
metascore="N/A"
imdbRating="8.2"
imdbVotes="1,159"
imdbID="tt2446042"
type="movie"
/>
</root>
如何从这种类型的XML中获取数据?就像说我希望得到“标题”和imdbRating这些数据,我应该走哪条路?
这是我的代码,但它确实不起作用......
Dim xml = XDocument.Load("config.xml")
MsgBox(xml.<root>.<movie>.<title>.value)
答案 0 :(得分:0)
您可以使用LINQ to XML来读取XDocument
类型。
首先,将这些导入添加到文件的顶部:
Imports System.Xml
Imports System.Xml.Linq
然后,您可以使用方法Element
和Attribute
来获取所需的元素:
Dim xml = XDocument.Load("config.xml")
MsgBox(xml.Element("root").Element("movie").Attribute("title").Value)
您可以找到有关LINQ to XML in MSDN
的其他信息