C# 解析图像数据的XML并返回图像字符串
我有一个轻微的逻辑问题。我正在解析从api调用返回的XML文件以显示在列表框中。xml数据返回一个对象键,而不是实际的图像。然后,我必须使用opject键调用另一个函数,该函数返回带有图像数据的xml,解析该图像数据并将其返回到前一个函数。我能够成功地将数据解析到IEnumerable列表中,但我不确定如何将图像字符串返回到上一次调用C# 解析图像数据的XML并返回图像字符串,c#,xml,string,parsing,return,C#,Xml,String,Parsing,Return,我有一个轻微的逻辑问题。我正在解析从api调用返回的XML文件以显示在列表框中。xml数据返回一个对象键,而不是实际的图像。然后,我必须使用opject键调用另一个函数,该函数返回带有图像数据的xml,解析该图像数据并将其返回到前一个函数。我能够成功地将数据解析到IEnumerable列表中,但我不确定如何将图像字符串返回到上一次调用 try { // MessageBox.Show(respo
try
{
// MessageBox.Show(response.Content);
XDocument streamFeed = XDocument.Load(new StringReader(response.Content));
var data = from query in streamFeed.Descendants("interaction")
select new Interaction
{
title = (string)query.Element("title"),
displayName = (string)query.Element("displayName"),
action = (string)query.Element("action"),
verb = (string)query.Element("verb"),
userId = (string)query.Element("userId"),
objectKey = (string)query.Element("objectKey"),
timestamp = (string)query.Element("timestamp"),
comment = (string)query.Element("comment"),
source = (string)query.Element("source"),
profileImage = "http://adb.s3.amazonaws.com/" + (string)query.Element("userId") + "/avatar.png",
image = getImage((string)query.Element("objectKey")),
};
streamListBox.ItemsSource = data;
上面的代码片段是将数据绑定到列表框的第一个函数。这非常有效,除了我需要xml响应中没有的图像。我必须进行第二个函数调用——getImage——以使用对象键获取它。我希望getImage函数只返回每个对象的字符串
try
{
// MessageBox.Show(response.Content);
XDocument streamFeed = XDocument.Load(new StringReader(response.Content));
var data = from query in streamFeed.Descendants("show")
select new Interaction
{
image = (string)query.Element("image"),
};
var data2 = from query in streamFeed.Descendants("movie")
select new Interaction
{
image = (string)query.Element("image"),
};
var data3 = from query in streamFeed.Descendants("artist")
select new Interaction
{
image = (string)query.Element("image"),
};
objImages = data.Concat(data2).Concat(data3);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
});
}
return "HOW CAN I RETURN IMAGE STRING HERE";
}
交互中“图像”属性的数据类型是什么?是绳子吗?如果它是字符串,那么它是一个URL吗?或者它是一个编码的二进制图像?还有,为什么要在第二个方法中连接data2和data3?嗨,image属性是一个字符串url,我只是在listbox中绑定它。concat将根据用户签入的.foreach(对象图像中的交互元素){{u objectImage=element.image;sendImage(_objectImage);}组合来自节目、电影和电影的图像我将所有URL作为字符串输出。问题是范围太广,我无法对单个图像使用return _objectimageyourproperty“image”这样的return语句,为什么需要一次返回3个?如果您需要发回三个,那么为什么不创建一个列表呢?嗨,3不是一次发回的,另外两个是在objectkey代表电视节目、电影或音乐的情况下,因为Decentant是不同的。每个对象键只返回一个图像(其他图像为空)