Hi folks,
I have an XML file which I need to modify in MS access.
In the XML file I have some code like this:
I need my vba code to find the <question> start tag and take the id and difficulty attributes and convert them to tags so the above will be:
I have built a small form for finding and replacing strings in text files with 3 text boxes where i can enter the file name, the text I want to replace and the replacement text. I want to modify the code i have for it (which is spliced-together code from some tutorials I found online).
The code I have is as follows:
I have tried but I cant get anywhere with it. My knowledge of this is lacking methinks.
Any help much appreciated.
I have an XML file which I need to modify in MS access.
In the XML file I have some code like this:
Code:
<question id="01" difficulty="easy">
<name>user1</name>
<body>Question blah blah</body>
<date>
<date year="2008" month="5" day="17" hour="2" minute="31" second="11"/>
</date>
</question>
I need my vba code to find the <question> start tag and take the id and difficulty attributes and convert them to tags so the above will be:
Code:
<question>
<id>01</id>
<difficulty>easy</difficulty>
<body>Question blah blah</body>
<date>
<date year="2008" month="5" day="17" hour="2" minute="31" second="11"/>
</date>
</question>
I have built a small form for finding and replacing strings in text files with 3 text boxes where i can enter the file name, the text I want to replace and the replacement text. I want to modify the code i have for it (which is spliced-together code from some tutorials I found online).
The code I have is as follows:
Code:
'Set a Reference to the Microsoft Scripting Runtime Library
Dim objFSO As FileSystemObject
Dim ts As TextStream
Dim strText As String
Dim strSearchText As String
Dim strFileName As String
Dim lngPos As Long
Dim lngStringCount As Long
Dim strNewText As String
Dim strReplaceText As String
Do
strSearchText = Me.searchtext
strReplaceText = Me.replacetext
strFileName = Me.fileselector
'Create instance of FileSystemObject.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile(strFileName, ForReading)
'Read entire contents of file, save to strText variable
strText = ts.ReadAll
lngPos = 1
lngPos = InStr(lngPos, strText, strSearchText)
If lngPos > 0 Then
lngStringCount = lngStringCount + 1
lngPos = lngPos + Len(strSearchText)
End If
ts.Close
strNewText = Replace(strText, strSearchText, strReplaceText, 1, 1, vbTextCompare)
FirstPos = 0
For i = 1 To 3
FirstPos = InStr(FirstPos + 1, strNewText, strSearchText, 1)
Next
Set ts = objFSO.OpenTextFile(strFileName, ForWriting)
ts.WriteLine strNewText
ts.Close
Loop Until lngPos = 0
MsgBox "The String [" & strSearchText & "] has been replaced by [" & strReplaceText & "] " & lngStringCount & " time(s) in the " & _
"File " & strFileName, vbInformation, "XML Processor"
I have tried but I cant get anywhere with it. My knowledge of this is lacking methinks.
Any help much appreciated.