XML在VB.net ListView中重复两次值 [英] XML Repeating values twice in VB.net ListView
本文介绍了XML在VB.net ListView中重复两次值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码将XML标签添加到ListView.我得到的结果是显示XML标记,但以重复的顺序
ListView1.Columns.Add(" , 100 ,HorizontalAlignment.Left)
Dim xpathDocument As XPathDocument
Dim xmlNavigator As XPathNavigator
暗 xmlNodeIterator As XPathNodeIterator
xpathDocument = 新建 XPathDocument(" )
xmlNavigator = xpathDocument.CreateNavigator()
xmlNodeIterator = xmlNavigator.选择(" )
xmlNavigator = xmlNodeIterator.Current
xmlNodeIterator = xmlNavigator.SelectDescendants(XPathNodeType.Element,真)
同时 xmlNodeIterator.MoveNext
ListBox1.Items.Add(xmlNodeIterator.Current.Name)
ListView1.Items.Add(xmlNodeIterator.Current.Name)
结束 同时
以下是我的XML
名称,价格,描述和卡路里这四个必须只出现一次,但它们重复两次.任何想法如何只显示一次
< xml 版本 =" 编码 =" ? < breakfast_menu >
< 食物 >
< 名称 > 比利时华夫饼干< /name >
< 价格 > $ 5.95 < /price >
< 描述 > 我们两个著名的比利时华夫饼,配以大量的真正的枫糖浆< /description >
< 卡路里 > 650 < /卡路里 >
< /food >
< 食物 >
< 名称 > 草莓比利时华夫饼< /name >
< 价格 > $ 7.95 < /price >
< 说明 > 比利时华夫饼覆盖着草莓和鲜奶油< /description >
< 卡路里 > 900 < /卡路里 >
< /food
</breakfast_menu >
解决方案
5.95 < /price < 描述 > 我们两个著名的比利时华夫饼,配以大量的真正的枫糖浆< /description > < 卡路里 > 650 < /卡路里 > < /food > < 食物 > < 名称 > 草莓比利时华夫饼< /name > < 价格 >
7.95 < /price > < 说明 > 比利时华夫饼覆盖着草莓和鲜奶油< /description > < 卡路里 > 900 < /卡路里 > < /food </breakfast_menu >
在codeproject上有一篇非常简单的文章,可以帮助您解决问题.
VB.NET中的XML文件解析 [ListView1.Columns.Add("Parameters", 100, HorizontalAlignment.Left) Dim xpathDocument As XPathDocument Dim xmlNavigator As XPathNavigator Dim xmlNodeIterator As XPathNodeIterator xpathDocument = New XPathDocument("C:\Users\Administrator\desktop\plant_catalog.xml") xmlNavigator = xpathDocument.CreateNavigator() xmlNodeIterator = xmlNavigator.Select("/admin/channel") xmlNavigator = xmlNodeIterator.Current xmlNodeIterator = xmlNavigator.SelectDescendants(XPathNodeType.Element, True) While xmlNodeIterator.MoveNext ListBox1.Items.Add(xmlNodeIterator.Current.Name) ListView1.Items.Add(xmlNodeIterator.Current.Name) End While
The below is my XML
Name, Price, Description and Calories these four have to come only once but they are repeating twice. any idea how to display only once
<xml version="1.0" encoding="ISO-8859-1" ?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>two of our famous Belgian Waffles with plenty of real maple syrup</description> <calories>650</calories> </food> <food> <name>Strawberry Belgian Waffles</name> <price>$7.95</price> <description>light Belgian waffles covered with strawberries and whipped cream</description> <calories>900</calories> </food </breakfast_menu>解决方案5.95</price> <description>two of our famous Belgian Waffles with plenty of real maple syrup</description> <calories>650</calories> </food> <food> <name>Strawberry Belgian Waffles</name> <price>
7.95</price> <description>light Belgian waffles covered with strawberries and whipped cream</description> <calories>900</calories> </food </breakfast_menu>
There is a very simple article on codeproject which will help sort you out.
XML File Parsing in VB.NET[^]
这篇关于XML在VB.net ListView中重复两次值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文