|
-
May 5th, 2007, 06:27 AM
#1
Thread Starter
New Member
XML Editing
Hello All,
I am currently trying to create a VB program that will take an XML document, search through it for certain specified fields and if I choose, change them. Then it will save it as a different titled XML file.
I first tried opening it in notepad format and changing via a text editor, however I can't save it correctly back into XML format.
I then found code for VB concerning XML files. Tweaking this a bit I am able to extract certain data, but I am unable to alter this data and save it as a retitled XML file.
Here is my code currently:
Code:
Option Explicit
Private m_AppPath As String
' 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
' Load saved values from XML.
Private Sub LoadValues()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode
' Load the document.
Set xml_document = New DOMDocument
xml_document.Load m_AppPath & "test 2.xml"
' If the file doesn't exist, then
' xml_document.documentElement is Nothing.
If xml_document.documentElement Is Nothing Then
' The file doesn't exist. Do nothing.
Exit Sub
End If
' Find the Values section.
Set values_node = xml_document.selectSingleNode("DynaMark-Project")
' Read the saved values.
txtBarcode.Text = GetNodeValue(values_node, "Text", "???")
End Sub
Private Sub Form_Load()
' Get the application's startup path.
m_AppPath = App.Path
If Right$(m_AppPath, 1) <> "\" Then m_AppPath = m_AppPath & "\"
' Load the values.
LoadValues
End Sub
My XML experience is non-existent basically, so any help would be very grateful. As you can see from the code I can extract the data into a text box, but if i change what is in the text box, I want to then alter the value in a similar XML file.
Can anyone help?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|