-1

您好,我在从 xml 文件中包含的 url 获取图片时遇到问题:

<item>
    <title>Music</title>
    <photo>http://www.jawharafm.net/jfmfiles/photos/hamdi.jpg</photo>
</item>

这是我的代码c#:

XElement xmlItems = XElement.Parse(e.Result);

listBox1.ItemsSource = from channel in xmlItems.Descendants("item")

let tit = channel.Element("title")

let pho = channel.Element("photo")

select new items
{
    title = tit == null ? null : tit.Value,
    photo = pho == null ? null : pho.Value,
};

我也有一个小问题,在解析文档后忽略样式应答器显示文本,如下所示:

<description>
    <![CDATA[<style>img { max-width: 310px; }</style><div>un concours mondial, appelé           "BlueHat"</span>, pour récompenser le ou la passionné d'informatique capable  <span    style="color: #3366ff;">10.000 dollars</span>.</div>
        <div /><span style="color: #ffffff;" />....]]>
</description>

谢谢

4

1 回答 1

1

在您对照片使用三元运算符的地方,您需要创建一个BitmapImage. 像这样的东西:

photo = pho == null ? null : new BitmapImage(new Uri(pho.Value))

鉴于这photo是一个BitmapImage本身。

样式标签到底有什么问题?由于您将其声明为 的一部分CDATA,因此它被正确读取并解释为标准字符串值。

于 2011-08-07T16:43:27.910 回答