DAO and XML

D

Dataman

Using ACC2003 and exporting a query as a xml file. When I do this, the file
looks like this:
--------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

<dataroot xmlns:blush:d="urn:schemas-microsoft-com:blush:fficedata"
generated="2008-01-23T14:54:12">

<DMRValuesItem>

<DMRRptId>263999</DMRRptId>

<DMRValId>6416445</DMRValId>

<PermitNum>WY0001234</PermitNum>

<Outfall>2341</Outfall>

<SBCode>cDX</SBCode>

<ParamID>30</ParamID>

</DMRValuesItem>

</dataroot>

------------------------------------------------------------------------------

The first two lines need to be removed and replaced with the
"<DMRValuesSet>" string right above "<DMRValuesItem>" string

The last line "</dataroot>" needs to be replaced with </DMRValuesItem> above
"<DMRValuesSet>"

The finished document should look like this:

<DMRValuesSet>

<DMRValuesItem>

<DMRRptId>263000</DMRRptId>

<DMRValId>6477739</DMRValId>

<PermitNum>WY0012345</PermitNum>

<Outfall>035</Outfall>

<SBCode>cDX</SBCode>

<ParamID>30</ParamID>

</DMRValuesItem>

</DMRValuesSet>

After I export the document I need to programmatically modify the document
as show above. I alread have the filename and path as a variable. This
document MUST be formatted as shown in the second example.

If someone has a code example please post it.

Thanks in advance for any help offered.

DM
 
R

Ralph

Not sure how to edit it, but the sub below will create a new file with the
changes.

Sub rwXML()
Dim fso As New FileSystemObject
Dim f As File
Dim tE As TextStream
Dim tW As TextStream
Dim strToWrite As String
Dim strCheck As String
Dim strToSkip() As String
Dim i As Integer
Dim bolFound As Boolean

strToSkip = Split("version,microsoft,dataroot", ",")

Set f = fso.GetFile("c:\temp\DMRValuesItem.xml")
fso.CreateTextFile ("c:\temp\DMRValuesItemNew.xml")
Set tW = fso.OpenTextFile("c:\temp\DMRValuesItemNew.xml", ForWriting)

Set tE = f.OpenAsTextStream

'first line of new file
tW.WriteLine ("<DMRValuesSet>")

Do While Not tE.AtEndOfLine
strToWrite = tE.ReadLine
For i = 0 To UBound(strToSkip)
If InStr(strToWrite, strToSkip(i)) > 0 Then
bolFound = True
End If
Next
If Not bolFound = True Then
tW.WriteLine strToWrite
End If
bolFound = False
Loop

tE.Close

'last line of new file
tW.WriteLine ("<DMRValuesSet>")
tW.Close

Set f = Nothing
Set tE = Nothing
Set tW = Nothing
Set fso = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top