我已经做了一些从xml文件读取的操作,所有操作都非常完美。但是有一件事是行不通的。
这是可以正常工作的xml部分
<title>lorum ipsum lorum ipsum</title>
这是我要阅读的xml部分:
<enclosure url="http://media.nu.nl/m/m1nxf1eaa6mh_sqr256.jpg" type="image/jpeg" />
我只想要url中的变量。
这就是我到目前为止所拥有的:
switch (node.Name)
{
case "title": label5.Text = (node.InnerText); break;
case "enclosure": string picbox2 = (node.InnerText); break;
pictureBox2.ImageLocation = picbox2;
case "description": label6.Text = (node.InnerText); i++; break;
}
我希望我提供了足够的信息。
在“附件”案例下,您有一个分配声明:pictureBox2.ImageLocation = picbox2;
在案例break;
声明之后。我不希望这会编译。
您还需要访问元素属性,element.Attributes["attr_name"].Value
而不是使用InnerText属性,该属性将带回开始和结束元素标签之间的文本。
switch (node.Name)
{
case "title":
label5.Text = (node.InnerText);
break;
case "enclosure":
string picbox2 = (node.Attributes["url"].Value);
pictureBox2.ImageLocation = picbox2;
break;
case "description":
label6.Text = (node.InnerText);
i++;
break;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句