我想访问下面的xml中的 introduce字段。
有没有简单的方法可以读取?谢谢了。最好是vb.net的
<?xml version="1.0" encoding="gb2312" ?>
<JLResponse>
  <HotelInfo>
    <Hotel>
      <Address>HotelAddress</Address> 
      <CityCode></CityCode> 
      <Star>StarRating</Star> 
      <Name>Hotelname</Name> 
      <Telephone>HotelTelephone</Telephone> 
      <FAX /> 
      <HotelDescription>
        <Introduce>HotelIntroduce</Introduce> 
        <Traffic>TrafficIntroduce</Traffic> 
      </HotelDescription>
      <Room>
        <RoomName>RoomName</RoomName> 
        <Description></Description> 
        <PublicPrice></PublicPrice> 
        <SalePrice></SalePrice> 
        <Availability>RoomStatus</Availability> 
        <RateChanged></RateChanged> 
        <PaymentType>PaymentType</PaymentType> 
        <Meal>Meal</Meal> 
      </Room>
    </Hotel>
  </HotelInfo>
</JLResponse>

解决方案 »

  1.   

    xml操作示例,里面只有一层节点,多层可以递归或循环读取childNodes:
    XmlDocument xmlRole = new XmlDocument();
    xmlRole.Load(HttpContext.Current.Server.MapPath(AppRoot + "xml/" + FileName));
    XmlElement root = xmlRole.DocumentElement;
    XmlNodeList nodeList = root.SelectNodes("Item");arrNodes = new XmlRecord[nodeList.Count];foreach(XmlNode nodeRole in nodeList)
    {
    arrNodes[intExtloop].ItemCode = nodeRole.Attributes["code"].Value.Trim();
    arrNodes[intExtloop].ItemCaption = nodeRole.Attributes"caption"].Value.Trim();
    intExtloop ++;
    }
      

  2.   

    能直接 连接我的这个xml 写一段代码给我吗?谢谢啦。麻烦了。
      

  3.   

    XmlDataDocument xDoc = new XmlDataDocument();
    xDoc.Load(Server.MapPath("1.xml"));
    XmlNode xn = xDoc.DocumentElement.SelectSingleNode("HotelInfo/Hotel/HotelDescription/Introduce");
    Response.Write(xn.InnerText);
      

  4.   

    Dim document1 As New XmlDataDocument
          document1.Load(MyBase.Server.MapPath("1.xml"))
          Dim node1 As XmlNode = document1.DocumentElement.SelectSingleNode("HotelInfo/Hotel/HotelDescription/Introduce")
          MyBase.Response.Write(node1.InnerText)
    vb.net的代码
      

  5.   

    XmlDocument doc = new XmlDocument();
    string fileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
    fileName = fileName.Substring(0,fileName.IndexOf("\\bin"));
    doc.Load(fileName + "\\GetXml.xml");
    XmlElement elem = doc.DocumentElement;
    XmlNode node = elem.ChildNodes[0].ChildNodes[0].ChildNodes[5].ChildNodes[0];
    string nodeText = node.InnerText;
      

  6.   

    GetXml.xml就是根据你的XML生成的文件,不过你的XML有点错误,就是<FAX /> 不完整,不删掉肯定出错!
    VB的是:Dim doc As New XmlDocument
                Dim fileName As String = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
                fileName = fileName.Substring(0, fileName.IndexOf("\\bin"))
                doc.Load(fileName + "\\GetXml.xml")
                Dim root As XmlElement = doc.DocumentElement
                Dim IntroduceNode As XmlNode = root.ChildNodes(0).ChildNodes(0).ChildNodes(5).ChildNodes(0)IntroduceNode 就是那个你要的节点
      

  7.   


            Dim document1 As New System.Xml.XmlDataDocument
            document1.Load(Me.Server.MapPath("1.xml"))
            Dim node1 As System.Xml.XmlNode = document1.DocumentElement.SelectSingleNode("HotelInfo/Hotel/HotelDescription/Introduce")
            Me.Response.Write(node1.InnerText)楼主试试,应该可以
      

  8.   

    chenyuming2004(这辈子我算是废了) 的方法就可以。不过你的VB代码可能是在vs2003下的。如果楼主用的是2005可能会报错。 我贴的是2005下的VB代码
      

  9.   

    呵呵C#代码是测试通过发上来的,
    vb.net的就不懂了,机子没装vb,而且我也不会vb.
    只是把我的C#代码,用软件换成vb的.
      

  10.   


    呵呵, 用软件换成vb的 。 估计是用2003的格式转的2005一些东东更严格chenyuming2004(这辈子我算是废了)的方法很简便~:)