日期:2014-05-16  浏览次数:20805 次

ASP读取XML的时候遇上空值,使用XPATH应该怎么处理呢?
假设有个这样的XML

<bookstore>
  <storename>小寨店</storename>
  <storetel>029-8888 8888</storetel>
  <storeaddr>西安市长安中路100号</storeaddr>
  <bookclass>
    <classname>社科类</classname>
    <classadmin>李四</classadmin>
    <classlist>
      <bookname>XXX时代</bookname>
      <bookprice>CNY90.00</bookprice>
      <bookpress/>
    </classlist>
  </bookclass>
  <bookclass>
    <classname>小说类</classname>
    <classadmin>王五</classadmin>
    <classlist>
      <bookname>冰与火之歌1</bookname>
      <bookprice>CNY70.00</bookprice>
      <bookpress>HBO出版社</bookpress>
      <bookname>冰与火之歌2</bookname>
      <bookprice>CNY70.00</bookprice>
      <bookpress>HBO出版社</bookpress>
      <bookname>冰与火之歌3</bookname>
      <bookprice>CNY70.00</bookprice>
      <bookpress>HBO出版社</bookpress>
    </classlist>
  </bookclass>
    <classname>IT类</classname>
    <classadmin>张三</classadmin>
    <classlist>
      <bookname>C语言基础教程</bookname>
      <bookprice>CNY20.00</bookprice>
      <bookpress>高等教育出版社</bookpress>
      <bookname>Think in C++</bookname>
      <bookprice>CNY90.00</bookprice>
      <bookpress>清华大学出版社</bookpress>
      <bookname>Think in Java</bookname>
      <bookprice>CNY89.00</bookprice>
      <bookpress>清华大学出版社</bookpress>
    </classlist>
  </bookclass>
</bookstore>

在读取bookclass节点的时候,如果其子节点(或者是孙节点,反正是下面的节点)中有个值是像例子里面那样,空的,直接用<bookpress/>的,就不读取了,直接读取下一个。

我今天试着用selectNodes("classlist/bookpress[not(text())]"),不行,不知道是哪里的问题。求各位高人解答..
XML是没办法改的,这是个webservice传递过来的的结果。

------解决方案--------------------
selectNodes("/bookstore/bookclass[classlist/bookpress[.!='']]")
------解决方案--------------------
Set objXML= CreateObject("MSXML2.DOMDocument")
'===<