我将如何阅读此 "XML" 类型?
How would I read this "XML" type?
这是回应 (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 中获取数据?比如说我想从这些数据中获取 "title" 和 imdbRating,我应该走哪条路?
这是我的代码,但它实际上不起作用...
Dim xml = XDocument.Load("config.xml")
MsgBox(xml.<root>.<movie>.<title>.value)
您可以使用 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
的更多信息
这是回应 (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 中获取数据?比如说我想从这些数据中获取 "title" 和 imdbRating,我应该走哪条路?
这是我的代码,但它实际上不起作用...
Dim xml = XDocument.Load("config.xml")
MsgBox(xml.<root>.<movie>.<title>.value)
您可以使用 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
的更多信息