" 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 formswill require that you make it Public. A good way of exposing it would be theSingleton Pattern: Public Class Settings Private Shared xmlDoc As XmlDocument Public Shared Property Products As XmlDocumentGetIf xmlDoc Is Nothing Then'' Initialize & load xmlDoc hereEnd If Return xmlDocEnd GetEnd 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 formore information on using XML in an application. "fremenusul" <fr********@discussions.microsoft.com> wrote in messagenews: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" asmuch 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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 06:02