Dave
I have slogged through saving my data to an XML it wasn't very easy to
learn about it but once I figured it out it is very easy to read and
navigate the file. there was no help in the VBA system so you have to
go to the MS site to find it and it is not geared for VBA so it was a
bit of work to figure it out. What helped me is to find the XML notepad
program which I set up a dummy file to help me figure out how I wanted
to format my data and then try and program it. here is a small snip it
of my code. it is used to save and retrieve my UDT which is used in
multiple drawings.
Option Explicit
Dim oDoc As DOMDocument
Dim oAlg As IXMLDOMElement
Dim oSta As IXMLDOMElement
Dim oLat1 As IXMLDOMElement
Dim oLat2 As IXMLDOMElement
Dim oRoot As IXMLDOMElement
Dim oStation As IXMLDOMAttribute
Public Sub Save_toXML()
Set oDoc = Nothing
Set oDoc = New DOMDocument
oDoc.async = False
On Error Resume Next
oDoc.Load (fXMLFile)
Set oRoot = oDoc.documentElement
'If Err.Number <> 0 Then
oDoc.resolveExternals = True
If oDoc.parseError <> 0 Then
' Create processing instruction and document root
Set oAlg = oDoc.createProcessingInstruction("xml", "version='1.0'")
Set oAlg = oDoc.insertBefore(oAlg, oDoc.childNodes.Item(0))
' Create document root
Set oRoot = oDoc.createElement("Project_" & CStr(Project))
Set oDoc.documentElement = oRoot
' oRoot.setAttribute "xmlns:dt", "urn:schemas-microsoft-com:datatypes"
'Else
'Set oRoot = oDoc.documentElement
End If
Err.Clear
Dim events As Variant, alignname As String
Dim x As Integer, name As String, name2 As String
name = Replace(algname, " ", "_")
alignname = "//Project_" & CStr(Project) & "//" & name
Set oAlg = oDoc.selectSingleNode(alignname)
name2 = oAlg.baseName
If name2 <> "" Then
For x = oAlg.childNodes.length - 1 To 0 Step -1
Set oSta = oAlg.childNodes.Item(x)
If Left(oSta.baseName, 3) = "Sta" Then
oAlg.removeChild oSta
End If
Next x
Else
Set oAlg = oDoc.createElement(name)
oRoot.appendChild oAlg
End If
oAlg.setAttribute "ALGNUMBER", align.Number
For x = LBound(AlignPt, 1) To UBound(AlignPt, 1)
Set oSta = oDoc.createElement("Sta" & Format(AlignPt(x).station,
"0.00"))
oAlg.appendChild oSta
Write_XMLStation oSta, oDoc, AlignPt(x)
Next x
' Save xml file
oDoc.Save fXMLFile
Set oDoc = Nothing
End Sub
Public Function Load_fromXML() As Boolean
Dim nodes As IXMLDOMNode
Set oDoc = Nothing
Set oDoc = New DOMDocument
oDoc.async = False
On Error Resume Next
oDoc.Load (fXMLFile)
'Set oRoot = oDoc.documentElement
'If Err.Number <> 0 Then
oDoc.resolveExternals = True
If oDoc.parseError = 0 Then
Dim alignname As String
Dim x As Integer, name As String, name2 As String, y As Integer
x = -1
name = Replace(algname, " ", "_")
alignname = "//Project_" & CStr(Project) & "//" & name
Set oAlg = oDoc.selectSingleNode(alignname)
Debug.Print Err.Number
name2 = oAlg.baseName
If name2 <> "" Then
If oAlg.getAttribute("ALGNUMBER") = align.Number Then
ReDim AlignPt(100)
For y = oAlg.childNodes.length - 1 To 0 Step -1
Set oSta = oAlg.childNodes.Item(y)
If Left(oSta.baseName, 3) = "Sta" Then
x = x + 1
Read_XMLStation oSta, AlignPt(x)
Load_fromXML = True
End If
Next y
ReDim Preserve AlignPt(x)
End If
End If
End If
Set oDoc = Nothing
End Function
Private Sub Write_XMLStation(oSta As IXMLDOMElement, oDoc As
DOMDocument, temp As junctions)
Dim oLat1 As IXMLDOMElement, oLat2 As IXMLDOMElement
oSta.setAttribute "Station", temp.station
oSta.setAttribute "Event", temp.Event
oSta.setAttribute "Direction", temp.direction
oSta.setAttribute "DirectionUP", temp.DirectionUP
oSta.setAttribute "Easting", temp.Easting
oSta.setAttribute "Northing", temp.Northing
oSta.setAttribute "Pipesize", temp.pipesize
oSta.setAttribute "PipesizeUP", temp.PipesizeUP
oSta.setAttribute "Flowline", temp.FlowLine
Set oLat1 = oDoc.createElement("Lateral1")
oSta.appendChild oLat1
oLat1.setAttribute "name", temp.Lateral1.name
oLat1.setAttribute "Station", temp.Lateral1.INTStation
oLat1.setAttribute "count", temp.Lateral1.count
oLat1.setAttribute "Direction", temp.Lateral1.direction
oLat1.setAttribute "eEast", temp.Lateral1.EndEasting
oLat1.setAttribute "eNorth", temp.Lateral1.EndNorthing
oLat1.setAttribute "eSta", temp.Lateral1.EndStation
Set oLat2 = oDoc.createElement("Lateral2")
oSta.appendChild oLat2
oLat2.setAttribute "name", temp.Lateral2.name
oLat2.setAttribute "Station", temp.Lateral2.INTStation
oLat2.setAttribute "count", temp.Lateral2.count
oLat2.setAttribute "Direction", temp.Lateral2.direction
oLat2.setAttribute "eEast", temp.Lateral2.EndEasting
oLat2.setAttribute "eNorth", temp.Lateral2.EndNorthing
oLat2.setAttribute "eSta", temp.Lateral2.EndStation
End Sub
Private Sub Read_XMLStation(oSta As IXMLDOMElement, temp As junctions)
Dim oLat1 As IXMLDOMElement, oLat2 As IXMLDOMElement
With temp
.station = oSta.getAttribute("Station")
.Event = oSta.getAttribute("Event")
.direction = oSta.getAttribute("Direction")
.DirectionUP = oSta.getAttribute("DirectionUP")
.Easting = oSta.getAttribute("Easting")
.Northing = oSta.getAttribute("Northing")
.pipesize = oSta.getAttribute("Pipesize")
.PipesizeUP = oSta.getAttribute("PipesizeUP")
.FlowLine = oSta.getAttribute("Flowline")
Set oLat1 = oSta.firstChild
.Lateral1.name = oLat1.getAttribute("name")
.Lateral1.INTStation = oLat1.getAttribute("Station")
.Lateral1.count = oLat1.getAttribute("count")
.Lateral1.direction = oLat1.getAttribute("Direction")
.Lateral1.EndEasting = oLat1.getAttribute("eEast")
.Lateral1.EndNorthing = oLat1.getAttribute("eNorth")
.Lateral1.EndStation = oLat1.getAttribute("eSta")
Set oLat2 = oSta.lastChild
.Lateral2.name = oLat2.getAttribute("name")
.Lateral2.INTStation = oLat2.getAttribute("Station")
.Lateral2.count = oLat2.getAttribute("count")
.Lateral2.direction = oLat2.getAttribute("Direction")
.Lateral2.EndEasting = oLat2.getAttribute("eEast")
.Lateral2.EndNorthing = oLat2.getAttribute("eNorth")
.Lateral2.EndStation = oLat2.getAttribute("eSta")
End With
End Sub
Dave F. wrote:
> Hi
>
> I've been using the registry to store/retrieve info between Acad sessions.
> But searching this NG there seems to be a movement against this. (Hello, Mr.
> Tuersley).
>
> Instead, so I read, I should be using ini files via win32api or XML.
>
> What are the reasons for this? Faster/slower, easier?
>
> Are there any examples to get me going?
> I've used the API a couple of times, but XML is new to me.
>
> Any help will be greatfully received
>
> TIA
> Dave F.
>
>