通过读取XML配置文件以哈希表结构进行保存。
Dim strMapInfoPath As String = System.Windows.Forms.Application.StartupPath() + "/MapConfiguration/DJTFHDMList.XML"
Dim doc As XmlDocument = New XmlDocument
If File.Exists(strMapInfoPath) Then
doc.Load(strMapInfoPath)
Dim rootNode As XmlNode = doc.Item("DJTFHDMList")
If rootNode Is Nothing Then
Return
End If
'取XML的节点
For Each featureCodeNode As XmlNode In rootNode.ChildNodes
Dim ClassLayerParameter As LayerParameter = New LayerParameter()
ClassLayerParameter.LayerName = featureCodeNode.Attributes("LayerName").Value
ClassLayerParameter.AliasName = featureCodeNode.Attributes("AliasName").Value
'属性字段
Dim attributesNode As XmlNode = featureCodeNode.Item("FHDMMappings")
If Not attributesNode Is Nothing Then
For Each attributesSubNode As XmlNode In attributesNode.ChildNodes
Dim ClassFieidsFHDMParameter As FieidsFHDMParameter = New FieidsFHDMParameter()
ClassFieidsFHDMParameter.FHDM = attributesSubNode.Attributes("FHDM").Value
ClassFieidsFHDMParameter.FHDMName = attributesSubNode.Attributes("FHDMName").Value
ClassFieidsFHDMParameter.Status = attributesSubNode.Attributes("Status").Value
ClassLayerParameter.PutFieidsFHDMParameter(ClassFieidsFHDMParameter.FHDM, ClassFieidsFHDMParameter)
Next
End If
m_hasTable.Add(ClassLayerParameter.LayerName, ClassLayerParameter)
Next
Else
MsgBox("找不到相关的文件", MsgBoxStyle.Information, "提示")
End If
Catch ex As Exception
MessageFactory.MessageService.ShowInformation("加载配置文件出错!")
End Try
配置文件样式:
<DJTFHDMList>
<LayerCode LayerName="CLKZD" AliasName="测量控制点">
<FHDMMappings>
<FHDMMappings FHDM="110102" FHDMName="三角点" Status="True" />
<FHDMMappings FHDM="110104" FHDMName="土堆上的三角点" Status="True" />
<FHDMMappings FHDM="110105" FHDMName="小三角点" Status="True" />
<FHDMMappings FHDM="110106" FHDMName="土堆上的小三角点" Status="True" />
</FHDMMappings>
</LayerCode>
</DJTFHDMList>