Ett nytt problem :) Kanske en början....Arbeta med en XML fil i VB
jag har kollat runt lite ang. detta... jag vill ha ett enkelt sätt att hantera en SML fil på.. läsa skriva ändra mm... det finns ingen databas inblandad utan bara data från en listview som jag vill ha in i en XML fil. nån som har en bra id'e??
//MartinSv: Arbeta med en XML fil i VB
<code>
Option Explicit
Private Sub Form_Load()
Dim i As Integer
Dim xItem As ListItem
For i = 1 To 10
Set xItem = ListView1.ListItems.Add(i, , "Item " & i)
xItem.SubItems(1) = "SubItem " & i
xItem.SubItems(2) = "SubSubItem " & i
xItem.SubItems(3) = "SubSubSubItem " & i
Next i
End Sub
Private Sub Create_XML_From_Listview()
Dim xmlDoc As New DOMDocument
Dim root As IXMLDOMElement
Dim currentElement As IXMLDOMElement
Dim newNode As IXMLDOMNode
Dim xmlContent As String
Dim blnOK As Boolean
Dim xItem As ListItem
Dim iColumn As Integer
xmlContent = "<ListView></ListView>"
blnOK = xmlDoc.loadXML(xmlContent)
Set root = xmlDoc.documentElement
If blnOK = True Then
'Loopa igenom alla rader i listviewn
For Each xItem In ListView1.ListItems
Set newNode = xmlDoc.createNode(NODE_ELEMENT, "Item_" & xItem.Index, "")
root.appendChild newNode
Set currentElement = root.selectSingleNode("Item_" & xItem.Index)
'Första kolumnen
Set newNode = xmlDoc.createNode(NODE_ELEMENT, ListView1.ColumnHeaders(1).Text, "")
newNode.Text = xItem.Text
currentElement.appendChild newNode
'Loopa alla subitems
For iColumn = 1 To ListView1.ColumnHeaders.Count - 1
Set newNode = xmlDoc.createNode(NODE_ELEMENT, ListView1.ColumnHeaders(iColumn + 1).Text, "")
newNode.Text = xItem.SubItems(iColumn)
currentElement.appendChild newNode
Next
Next
xmlDoc.save "c:\listview.xml"
Set root = Nothing
Set newNode = Nothing
Set currentElement = Nothing
Else
MsgBox Err.Description
End If
End Sub
</code>