dinilkarun 8 Posting Whiz in Training

Hi,

I am trying to save a Vb form values to XML, I am able to write to a XML, but i am not able to append more pages.
I am using the following code:


' Save the current values.
Private Sub SaveValues()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode

' Create the XML document.
Set xml_document = New DOMDocument

' Create the Values section node.
Set values_node = xml_document.createElement("Book")

' Add a newline.
values_node.appendChild xml_document.createTextNode(vbCrLf)

' Add the Values section node to the document.
xml_document.appendChild values_node
' Create nodes for the values inside the
' Values section node.
CreateNode 4, values_node, "TitleoftheBook", Text2.Text
CreateNode 4, values_node, "ImageNo", Text1.Text
CreateNode 4, values_node, "PageNo", Text3.Text
CreateNode 4, values_node, "Details", Combo1.Text + "" + Text5.Text
CreateNode 4, values_node, "Remarks", Text4.Text
'CreateNode 4, values_node, "Zip", txtZip.Text

' Save the XML document.
m_AppPath = Display.Label2.Caption
xml_document.save m_AppPath & "Meta1.xml"
'xml_document.save "Meta1.xml"
End Sub

Private Sub Command1_Click()
SaveValues
MsgBox (" File Saved ")
Unload Me
End Sub
Private Sub CreateNode(ByVal indent As Integer, ByVal parent As IXMLDOMNode, ByVal node_name As String, ByVal node_value As String)
Dim new_node As IXMLDOMNode

' Indent.
parent.appendChild parent.ownerDocument.createTextNode(Space$(indent))

' Create the new node.
Set new_node = parent.ownerDocument.createElement(node_name)

' Set the node's text value.
new_node.Text = node_value

' Add the node to the parent.
parent.appendChild new_node

' Add a newline.
parent.appendChild parent.ownerDocument.createTextNode(vbCrLf)
End Sub
' Return the node's value.
Private Function GetNodeValue(ByVal start_at_node As IXMLDOMNode, ByVal node_name As String, Optional ByVal default_value As String = "") As String
Dim value_node As IXMLDOMNode

Set value_node = start_at_node.selectSingleNode(".//" & node_name)
If value_node Is Nothing Then
GetNodeValue = default_value
Else
GetNodeValue = value_node.Text
End If
End Function


The output I am getting is:

<Book>
<TitleoftheBook>182002_OU_Saarandhaa</TitleoftheBook>
<ImageNo>00000001</ImageNo>
<PageNo>1</PageNo>
<Details>Title</Details>
<Remarks>title of the page is saaran'dhaa</Remarks>
</Book>

But I want the output to be:

<Book>
<TitleoftheBook>182002_OU_Saarandhaa</TitleoftheBook>
<ImageNo>00000001</ImageNo>
<PageNo>1</PageNo>
<Details>Title</Details>
<Remarks>title of the page is saaran'dhaa</Remarks>

<ImageNo>00000002</ImageNo>
<PageNo>2</PageNo>
<Details>Title</Details>
<Remarks>second page</Remarks>
...
...


</Book>

I want to add more like how I have shown above.. but its overwriting, on the same one set. Pls help me how to append to the XML file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.