XML Visual Basic问题 [英] XML Visual Basic Questions

查看:56
本文介绍了XML Visual Basic问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说我熟悉编程,但不熟悉VB.net。


我正在使用此程序加载现有的XML文档

Dim xmlFile As String =" .. \data\Products.xml"

Dim xmlDoc As XmlDocument


Private Sub Zadig_Load (ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

Dim xmlTr As New XmlTextReader(xmlFile)

>
而xmlTr.Read

如果xmlTr.Name =" id" AndAlso xmlTr.NodeType =

XmlNodeType.Element然后

cmbProducts.Items.Add(xmlTr.ReadString)

结束如果

结束时

xmlTr.Close()


xmlDoc =新的XmlDocument

xmlDoc.Load(xmlFile)


结束子


如果我有一个新表格(IE-Products.vb),我是否可以参考XML
内存中的
doc?


另外,是否有一个很好的Web引用,显示如何更新

XML数据(在内存中)然后写他们退回到档案?


谢谢,


迈克尔

First let me say I am familar with programming, but not familiar with VB.net.

I am loading an existing XML document with this procedure

Dim xmlFile As String = "..\data\Products.xml"
Dim xmlDoc As XmlDocument

Private Sub Zadig_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xmlTr As New XmlTextReader(xmlFile)

While xmlTr.Read
If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
XmlNodeType.Element Then
cmbProducts.Items.Add(xmlTr.ReadString)
End If
End While
xmlTr.Close()

xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)

End Sub

If I have a NEW form (IE-Products.vb), will I be able to reference the XML
doc in Memory?

Also, is there a good web reference that shows how to update
XML data (In memory) and then write them back out to a file?

Thanks,

Michael

推荐答案

Fremenusul。


当你开始使用VBNet或beter dotNet并使用XML时,你首先要自己拥有

首先是这个一个数据文件或一个文件。


当它是一个数据文件时,你首先要看一下数据集,因为

有自己的方法处理元素,比这更容易

loaddoc和xmlreader。


如果您有更多问题,请回复


Cor
Fremenusul.

When you start with VBNet or beter dotNet and will use XML, you have
yourself first is this an data file or a document.

When it is a data file you would first have a look at the dataset, because
that has its own methods to handle elements, which are a lot easier than the
loaddoc and the xmlreader.

When you have more questions, please reply

Cor


表单Zadig的每个实例都有自己的xmlDoc变量副本,

但其他表单类型不会。要共享xmlDoc变量amoungst表单

将要求您将其设置为Public。暴露它的好方法是

Singleton模式:


公共类设置


私有共享xmlDoc作为XmlDocument


公共共享属性产品为XmlDocument

获取

如果xmlDoc什么都没有那么

''初始化&在这里加载xmlDoc

结束如果


返回xmlDoc

结束获取

结束物业

结束班级


然后访问你要做的XmlDocument:

Settings.Products


看看

_blank> http://samples.gotdotnet.com/quickst...viewofxml.aspx
有关在应用程序中使用XML的更多信息。

" fremenusul" < FR ******** @ discussions.microsoft.com>在留言中写道

新闻:AB ********************************** @ microsof t.com ...
Each instance of form Zadig will have it''s own copy of the xmlDoc variable,
but other form types will not. To share the xmlDoc variable amoungst forms
will require that you make it Public. A good way of exposing it would be the
Singleton Pattern:

Public Class Settings

Private Shared xmlDoc As XmlDocument

Public Shared Property Products As XmlDocument
Get
If xmlDoc Is Nothing Then
'' Initialize & load xmlDoc here
End If

Return xmlDoc
End Get
End Property

End Class

Then to access the XmlDocument you''d just do:
Settings.Products

Have a look at
http://samples.gotdotnet.com/quickst...viewofxml.aspx for
more information on using XML in an application.

"fremenusul" <fr********@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
首先让我说我熟悉编程,但不熟悉VB.net。

我正在加载现有的XML使用此过程的文档

Dim xmlFile As String =" .. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
Dim xmlTr作为新的XmlTextReader(xmlFile)

而xmlTr.Read
如果xmlTr.Name =" id" AndAlso xmlTr.NodeType =
XmlNodeType.Element然后
cmbProducts.Items.Add(xmlTr.ReadString)
结束如果
结束时
xmlTr.Close()

xmlDoc =新的XmlDocument
xmlDoc.Load(xmlFile)

结束子

如果我有一个新的表格(IE-Products.vb ),我能在内存中引用XML
doc吗?

另外,是否有一个很好的Web引用,显示如何更新XML数据(在内存中)和然后把它们写回文件?

谢谢,

Michael
First let me say I am familar with programming, but not familiar with
VB.net.

I am loading an existing XML document with this procedure

Dim xmlFile As String = "..\data\Products.xml"
Dim xmlDoc As XmlDocument

Private Sub Zadig_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xmlTr As New XmlTextReader(xmlFile)

While xmlTr.Read
If xmlTr.Name = "id" AndAlso xmlTr.NodeType =
XmlNodeType.Element Then
cmbProducts.Items.Add(xmlTr.ReadString)
End If
End While
xmlTr.Close()

xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)

End Sub

If I have a NEW form (IE-Products.vb), will I be able to reference the XML
doc in Memory?

Also, is there a good web reference that shows how to update
XML data (In memory) and then write them back out to a file?

Thanks,

Michael



为什么是数据文件更好?我正在学习并想要理解为什么的 as

就像怎么样一样。


谢谢,


Michael


" Cor Ligthert"写道:
Why is datafile better? I am learning and want to understand the "why''s" as
much as the "how''s".

Thanks,

Michael

"Cor Ligthert" wrote:
Fremenusul。

当你从VBNet或beter dotNet开始并将使用XML时,你首先要自己这是一个数据文件当它是一个数据文件时,你首先要看一下数据集,因为
有自己的方法来处理元素,这比<当你有更多问题时,请回复

Cor
Fremenusul.

When you start with VBNet or beter dotNet and will use XML, you have
yourself first is this an data file or a document.

When it is a data file you would first have a look at the dataset, because
that has its own methods to handle elements, which are a lot easier than the
loaddoc and the xmlreader.

When you have more questions, please reply

Cor



这篇关于XML Visual Basic问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆