Is there a way to construct the DOM tree from memory and not from an XML file?
Is there a way to convert DOM tree into XML and prints it into file and not to the screen?
hi.
im not sure that this is what you need but anyway here some example code in vb that shows loading un saving a file.xml
(this code also comes with some gui components to view the data):
Option Explicit
Private xmlDoc As DOMDocument
Private style As IXMLDOMNode
Private nodesList As IXMLDOMNodeList
Private m_AppPath As String
' Add a new node to the indicated parent node.
Private Function createNode(ByVal indent As Integer, ByVal parent As IXMLDOMNode, ByVal node_name As String, ByVal style As String) As IXMLDOMNode
Dim newNode As IXMLDOMNode
parent.appendChild parent.ownerDocument.createTextNode(vbCrLf)
' Indent.
parent.appendChild parent.ownerDocument.createTextNode(Space$(indent))
' Create the new node.
Set newNode = parent.ownerDocument.createElement(node_name)
' Set the node's text value.
newNode.Text = style
Set createNode = newNode
End Function
Private Sub appNode(ByVal parent As IXMLDOMNode, ByVal newNode As IXMLDOMNode)
'appends node to parent
parent.appendChild newNode
parent.appendChild parent.ownerDocument.createTextNode(vbCrLf)
End Sub
' Load saved values from XML file.
Public Sub loadValues()
' Load the document.
xmlDoc.Load m_AppPath & "Values.xml"
If xmlDoc.documentElement Is Nothing Then
MsgBox (m_AppPath & "Values.xml"
Exit Sub
End If
'set the parent node
Set style = xmlDoc.selectSingleNode("Style"
'insert all child nodes into object nodesList
Set nodesList = xmlDoc.selectNodes("Style/Atr"
makeList
End Sub
Private Sub makeList()
Dim i As Integer
For i = 0 To nodesList.length - 1
List1.AddItem nodesList.Item(i).Text
Next
End Sub
Public Sub addValues()
Dim newNode As IXMLDOMNode
'create node
Set newNode = createNode(4, style, "Atr", att.Text)
'append node
appNode style, newNode
' Save the XML document.
List1.AddItem (att.Text)
List1.Refresh
Set newNode = Nothing
End Sub
Public Sub saveValues()
xmlDoc.save m_AppPath & "Values.xml"
End Sub
Public Sub updateNode()
nodesList.Item(List1.ListIndex).Text = att.Text
List1.AddItem att.Text, List1.ListIndex
List1.RemoveItem List1.ListIndex
List1.Refresh
End Sub
Public Sub removeNode()
Dim node As IXMLDOMNode
Set node = nodesList.Item(List1.ListIndex)
style.removeChild node
Set node = Nothing
List1.RemoveItem (List1.ListIndex)
List1.Refresh
End Sub
Private Function isSelected() As Boolean
Dim flag As Boolean
flag = True
If List1.ListIndex = -1 Then
MsgBox ("You have to select an item first"
flag = False
End If
isSelected = flag
End Function
Private Function isFilled() As Boolean
Dim flag As Boolean
flag = True
If att.Text = "" Then
MsgBox ("You have to insert a value first"
flag = False
End If
isFilled = flag
End Function
Private Sub Command1_Click()
saveValues
End Sub
Private Sub Command2_Click()
If Not isSelected Or Not isFilled Then Exit Sub
updateNode
End Sub
Private Sub Command3_Click()
If Not isSelected Then Exit Sub
removeNode
End Sub
Private Sub Command4_Click()
If Not isFilled Then Exit Sub
addValues
End Sub
Private Sub Form_Load()
' Get the application's startup path.
Set xmlDoc = New DOMDocument
m_AppPath = App.Path
If Right$(m_AppPath, 1) <> "\" Then m_AppPath = m_AppPath & "\"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.