您好,我正在使用下面给出的 xml 文件,我尝试了很多代码从 xml 文件中获取多个列表,但我无法获取。
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Categories>
<Category name="Photos">
<Articles>
<article title="Sherawat's">
<Description>
Hottie Sherawat
</Description>
<FullContent>
<style> img {padding:2px;} </style><p> <img alt=" Sherawat" pimcore_disable_thumbnail="true" pimcore_id="5853" pimcore_type="asset" src="http://feb2013/bolly---sherawat-s-upcoming-movie-dirty-politics/90_mallika-sherawat_bolly.jpg" style="width: 500px; height: 370px; float: left;" /></p> <p>Sherawat is all set to begin shooting for <em>Dirty Politics</em> where she plays Bhanwari Devi, a nurse whose murder hit the headlines last year. Meanwhile, she gets talking on Hollywood where she has not really had any meaty roles.</p>
</FullContent>
<thumb_image>
<image url="http://sss.com/Photo1.jpeg"/>"/>
</thumb_image>
</article>
<article articleid="2684" title="Steals the Mai Show">
<Description>
<p> Actor Hrithik Roshan has always nursed a dream of working with acclaimed Director Kapur.</p>
</Description>
<FullContent>
<div id="container" class="cf">
<link rel="stylesheet" href="http://sss.com/imageslider/app/css/demo.css" type="text/css" media="screen" />
<link rel="stylesheet" href="http://sss.com/imageslider/app/css/flexslider.css" type="text/css" media="screen" />
<div id="main" role="main"> <section class="slider"> <div class="flexslider"> <ul class="slides">
<li>Sonam Kapoor<img src="http://sss.com//website/var/tmp/thumb_5814_1_01feb2013__appfeed.jpeg" alt="Kapoor"/></li>
</ul>
</li>
</div>
</FullContent>
<thumb_image>
<image url="http://Photo2.jpeg"/>"/>
</thumb_image>
</article>
</Articles>
</Category>
<Category name="Videos">
<Articles>
<article articleid="415" title=" Dirty Politics">
<Description>
Sherawat speaks about the men whom she’s over the moon about
</Description>
<FullContent>
<style> img {padding:2px;} </style><p> <img alt="Sherawat" pimcore_disable_thumbnail="true" pimcore_id="5853" pimcore_type="asset" src="http://sss.com/bolly/feb2013/bolly---sherawat-s-upcoming-movie-dirty-politics/90_sherawat_bolly.jpg" style="width: 500px; height: 370px; float: left;" /></p>
</FullContent>
<thumb_image>
<image url="http://Video1.jpeg"/>"/>
</thumb_image>
</articles>
<article articleid="68" title="Digital!">
<Description>
<p> Touch, tap, flip, slide! You don't, you experience it.</p>
</Description>
<FullContent>
<p> Touch, tap, flip, slide! You don'you experience it.</p> <br/><br/><br/> <br/><br/>
</FullContent>
<thumb_image>
<image url="http://Video2.jpeg"/>"/>
</thumb_image>
</article>
</Article>
</Category>
<Category name="Bolly">
<Articles>
<article articleid="415" title="upcoming movie">
<Description>
the men whom she’s over the moon about
</Description>
<FullContent>
<style> img {padding:2px;} </style><p> <img alt="Sherawat" pimcore_disable_thumbnail="true" pimcore_id="5853" pimcore_type="asset" src="http://sss.com/bolly/feb2013/bolly---sherawat-s-upcoming-movie-dirty-politics/90_sherawat_bolly.jpg" style="width: 500px; height: 370px; float: left;" /></p>
</FullContent>
<thumb_image>
<image url="http://sss.com/website/var/tmp/thumb_5854_90_mallika-sherawat_thumb_bolly__forfeed.jpeg"/>
</thumb_image>
</articles>
<article articleid="436" title="Surprise Package">
<Description>
There was more than just good music at the trio's recent performance
</Description>
<FullContent>
<style> img {padding:2px;} </style><p> <img alt="Akcent" pimcore_disable_thumbnail="true" pimcore_id="6110" pimcore_type="asset" src="http://dev2.mercuryminds.com/global/feb2013/surprise-package-at-akcent-concert/18_akcent_global.jpg" style="width: 370px; height: 500px; float: left;" /></p>
</FullContent>
<thumb_image>
<image url="http://sss.com/website/var/tmp/thumb_6109_18_akcent_thumb__forfeed.jpeg"/>
</thumb_image>
</article>
</Article>
</Category>
</Categories>
</root>
我的 MainPageXaml.cs 代码
public MainPage()
{
InitializeComponent();
WebClient downloader = new WebClient();
Uri uri = new Uri("http://sss.com/webservices/new_feed_articls.xml", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(NotchsDownloaded);
downloader.DownloadStringAsync(uri);
}
void NotchsDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
ParseXMLFile(e.Result);
}
}
void ParseXMLFile(string dataInXmlFile)
{
try
{
//Parsing XML File
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
var query = from l in xmlDoc.Descendants("Category")
select new Data
{
name = (string)l.Attribute("name").Value,
Titles = l.Element("Articles").Elements("article")
.Select(s => s.Attribute("title").Value)
.ToList(),
Image = l.Element("Articles").Elements("article")
.Elements("thumb_image").Elements("image")
.Select(x => x.Attribute("url").Value).ToList()
};
foreach (var result in query)
{
Console.WriteLine(result.name);
foreach (var detail in result.Titles)
{
Console.WriteLine(detail);
}
}
List.ItemsSource = query.ToList();
}
catch(Exception e)
{
}
}
我的类(class)文件
public class Data
{
[XmlAttribute("name")]
public string name { get; set; }
[XmlAttribute("title")]
public List<string> Titles { get; set; }
[XmlAttribute("url")]
public List<string> Image { get; set; }
[XmlElement("Description")]
public string Description { get; set; }
[XmlElement("FullContent")]
public string FullContent { get; set; }
}
[XmlRoot("root")]
public class DataArray
{
[XmlArray("Categories")]
[XmlArrayItem("Category")]
[XmlArrayItem("Articles")]
[XmlArrayItem("article")]
public ObservableCollection<Data> Collection { get; set; }
}
我的 XAML 文件
<ListBox x:Name="List" ItemsSource="{Binding}"
Margin="0,-0.25,2,-6" Grid.Row="3" HorizontalAlignment="Right" Width="478" d:LayoutOverrides="VerticalMargin" Grid.RowSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,0" Orientation="Vertical" Grid.ColumnSpan="2" Grid.RowSpan="3" x:Name="ControlsPanel"
Grid.Column="0"
Height="160"
VerticalAlignment="Top">
<StackPanel Background="#eb2427" Orientation="Vertical">
<TextBlock Grid.Row="1" FontFamily="Calibri" FontSize="34" FontWeight="Bold" FontStyle="Normal" Margin="10,0,0,0"
Text="{Binding name}"
/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Row="1" FontFamily="Calibri" FontSize="32" Foreground="#a7a9ac" Width="Auto"
Text="{Binding Titles}" TextWrapping="Wrap" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
</StackPanel>
<StackPanel>
<Image Source="{Binding Image}" Width="Auto"></Image>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我尝试了很多代码,但我得到了相同的结果。输出没有变化。我在我的输出屏幕短裤下面给出了
我想要这样的输出
嗨,我尝试了很多方法,但很长时间都无法解决这个问题。所以现在我告诉你我的期望。请任何人考虑我的问题并给我任何代码来解决这个问题。
最佳答案
首先,将 Image 属性重命名为 Images,因为它是一个图像列表,而不是单个图像。
然后,在 XAML 代码中,将该图像列表的显示方式从显示一个图像调整为显示多个。这与显示集合的方式相同 - 通过使用 ListBox(或其他适当的 ItemsControl)。将 XAML 更改为:
<ListBox ItemsSource="{Binding Image}">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Width="Auto"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这将显示一个图像列表,而不是显示一个包含一个图像的 StackPanel。但它会垂直显示它们而不是水平显示。查看以下主题以获取更多信息:How do I get a Horizontal ListBox to scroll horizontally in WP7? .
关于windows - 如何在 Windows Phone 7 中绑定(bind)来自 xml 文件的动态多列表数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15518176/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"