代码

Imports System.Web.Util
Imports System.Xml
Imports System.Xml.XPath

 

  '在此处放置初始化页的用户代码
        Dim doc As XmlDocument = New XmlDocument

        If Not IsPostBack Then

 

            '   Dim strtt As String = Server.MapPath("XMLCar.xml")
            doc.Load(Server.MapPath("..\data\XMLCar.xml"))
            Dim book As XmlNode

            Dim root As XmlNode
            dlpp.Items.Clear()

            Dim elemList As XmlNodeList = doc.GetElementsByTagName("brandName") '获取品牌
            Dim i As Integer
            For i = 0 To elemList.Count - 1

                dlpp.Items.Add(elemList.ItemOf(i).InnerXml)


            Next
            If dlpp.Items.Count > 0 Then
                dlpp.SelectedIndex = 0

                elemList = doc.SelectNodes("descendant::Carbrand[brandName='" + dlpp.SelectedItem.Text + "']/Carmodel/modelName")
                dlmod.Items.Clear()
                For i = 0 To elemList.Count - 1

                    dlmod.Items.Add(elemList.ItemOf(i).InnerXml)


                Next

                If dlpp.Items.Count > 0 Then
                    dlmod.SelectedIndex = 0

                    elemList = doc.SelectNodes("descendant::Carbrand[brandName='" + dlpp.SelectedItem.Text + "']//Carmodel[modelName='" + dlmod.SelectedItem.Text + "']/Carcolor/colorName")
                    dlcl.Items.Clear()
                    For i = 0 To elemList.Count - 1

                        dlcl.Items.Add(elemList.ItemOf(i).InnerXml)


                    Next
                    dlcl.SelectedIndex = 0

                End If
            End If

XML文件

<?xml version="1.0" standalone="yes"?>
<dbCar>
  <Carbrand>
    <brandName>丰田</brandName> <!-- 品牌 -->
       <Carmodel> 
              <modelName>型号1</modelName> <!-- 型号 -->
                  <Carcolor>  <!-- 颜色 -->
                       <colorName>红色</colorName>
                       <colorName>蓝色</colorName>
                       <colorName>yyy</colorName>                     
                  </Carcolor>
    </Carmodel>
     <Carmodel> 
              <modelName >型号2</modelName> <!-- 型号 -->
                   <Carcolor>  <!-- 颜色 -->
                       <colorName>红色</colorName>
                       <colorName>蓝色</colorName>
                       <colorName>xxx</colorName>                     
                  </Carcolor>
    </Carmodel>
     <Carmodel> 
              <modelName>555</modelName> <!-- 型号 -->
                   <Carcolor>  <!-- 颜色 -->
                       <colorName>红色</colorName>
                       <colorName>蓝色</colorName>
                       <colorName>zzz</colorName>                     
                  </Carcolor>
    </Carmodel>
  </Carbrand>
   <Carbrand>
    <brandName>本田</brandName> <!-- 品牌 -->
      <Carmodel> 
              <modelName>型号1</modelName> <!-- 型号 -->
                  <Carcolor>  <!-- 颜色 -->
                       <colorName>红色</colorName>
                       <colorName>蓝色</colorName>
                       <colorName>1111</colorName>                     
                  </Carcolor>
    </Carmodel>
     <Carmodel> 
              <modelName>型号2</modelName> <!-- 型号 -->
                   <Carcolor>  <!-- 颜色 -->
                       <colorName>红色</colorName>
                       <colorName>蓝色</colorName>
                       <colorName>333</colorName>                     
                  </Carcolor>
    </Carmodel>
     <Carmodel> 
              <modelName>666</modelName> <!-- 型号 -->
                   <Carcolor>  <!-- 颜色 -->
                       <colorName>红色</colorName>
                       <colorName>蓝色</colorName>
                       <colorName>222</colorName>                     
                  </Carcolor>
    </Carmodel>
  </Carbrand>
</dbCar>

 

 

posted on 2006-05-30 09:23  公木子  阅读(153)  评论(0编辑  收藏  举报