My problem is the following: I'am trying deserialize a XML doc (see it below).
offer id="68985117" categoryId="2921">
<offerName>CD Metallica - Some Kind of Monster ( 5314040 )</offerName>
<offerShortName>Cd Metallica Some</offerShortName>
<links>
<link type="offer" url="http://.."/>
<thumbnail url="http://thumbs.buscape.com.br/T100x100/__2.81-41ca11d.jpg"/>
<price>
<currency abbreviation="BRL"/>
<value>19.90</value>
I'am reading [offerName] using XML
offername = x.GetElementsByTagName("offerName")[0].InnerText,
and value by
offervalue = x.GetElementsByTagName("value")[0].InnerText
My question: how can i take the link url and thumbnail url?
Use the GetAttribute() method of XmlElement
string url = x.GetElementsByTagName("link")[0].GetAttribute("url");
Here is a complete example
XmlDocument x = new XmlDocument();
x.LoadXml("<xml goes here/>");
string offername = x.GetElementsByTagName("offerName")[0].InnerText;
string offervalue = x.GetElementsByTagName("value")[0].InnerText;
string linkUrl = x.GetElementsByTagName("link")[0].Attributes["url"].Value;
string thumb = x.GetElementsByTagName("thumbnail")[0].Attributes["url"].Value;
获取元素(即缩略图),然后从Attribute集合中选择url属性。
var thumbnailUrl = x.GetElementsByTagName("thumbnail")[0].GetAttribute["url"].Value;
var linklUrl = x.GetElementsByTagName("link")[0].GetAttribute["url"].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.