| | |
VB to XML
![]() |
•
•
Join Date: Feb 2008
Posts: 198
Reputation:
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.
![]() |
Similar Threads
- 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)
- 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
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





