•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 422,389 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,756 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 600 | Replies: 0
![]() |
•
•
Join Date: Feb 2008
Posts: 108
Reputation:
Rep Power: 1
Solved Threads: 0
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Reading stream with two xml files in (Java)
- html vs. XML (JavaScript / DHTML / AJAX)
- Java and XML (Java)
- Pass XML file contents to a hash table. (Java)
- ASP.NET <--> XML <--> VB6.0 (ASP.NET)
- help required for implementing project using JAVA & XML (Java)
- searches appearing as .xml files in windows folder (Windows NT / 2000 / XP / 2003)
- Php parser error when xml version is mentioned (PHP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: usb interfacing
- Next Thread: RE:SourceSafe Control


Linear Mode