我无法在vb.net中拆分xml数据

时间:2018-05-08 13:12:10

标签: xml vb.net

我正在尝试拆分xml文件

这是我自动创建的xml:

<?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
        <ns2:genelSorguResponse xmlns:ns2="http://genel.service.ws.epvys.g222.tubitak.gov.tr/">
          <return>
            <PetrolPiyasasiIllereGoreAkaryakitFiyatlariResult>
              <PetrolPiyasasiIllereGoreAkaryakitFiyatlari>
                <Tarih>2018-04-28 00:00:00.0</Tarih>
                <YakitTipi>Kurşunsuz Benzin 95 Oktan</YakitTipi>
                <Il>İSTANBUL (AVRUPA)</Il>
                <FirmaMarkasi>7KITA</FirmaMarkasi>
                <Fiyat>0.0</Fiyat>
              </PetrolPiyasasiIllereGoreAkaryakitFiyatlari>
            </PetrolPiyasasiIllereGoreAkaryakitFiyatlariResult>
          </return>
         </ns2:genelSorguResponse xmlns:ns2="http://genel.service.ws.epvys.g222.tubitak.gov.tr/">
      </S:Body>
    </S:Envelope>

这是我的代码:

dim dosyaAdi = "yakit_" & now.day & "." & now.month & "." & now.year & ".xml"
 Dim m_xmld As XmlDocument
    Dim m_nodelist As XmlNodeList
    Dim m_node As XmlNode

    m_xmld = New XmlDocument()

    m_xmld.Load("C:\Milenyum\yakitkontrol\" & dosyaAdi)

    m_nodelist = m_xmld.SelectNodes("return/PetrolPiyasasiIllereGoreAkaryakitFiyatlariResult/PetrolPiyasasiIllereGoreAkaryakitFiyatlari")

    For Each m_node In m_nodelist

      Dim FirmaMarkasi = m_node.ChildNodes.Item(3).InnerText

      Dim YakitTipi = m_node.ChildNodes.Item(1).InnerText

      Dim fiyat = m_node.ChildNodes.Item(4).InnerText


      if FirmaMarkasi = "OPET" and YakitTipi="Motorin" then
      sonucTutar = fiyat.toString.replace(".", ",")
      end if

    Next

使用该代码我无法访问我想要的数据。

但是当我从xml文件中删除这些代码时:

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
          <S:Body>
            <ns2:genelSorguResponse xmlns:ns2="http://genel.service.ws.epvys.g222.tubitak.gov.tr/">
</ns2:genelSorguResponse xmlns:ns2="http://genel.service.ws.epvys.g222.tubitak.gov.tr/">
      </S:Body>
    </S:Envelope>

我可以访问我想要的任何数据。但是xml文件会自动创建,所以我每次都需要编辑xml文件。还有其他方法吗?提前谢谢

1 个答案:

答案 0 :(得分:0)

m_nodelist = m_xmld.SelectNodes("//return/PetrolPiyasasiIllereGoreAkaryakitFiyatlariResult/PetrolPiyasasiIllereGoreAkaryakitFiyatlari")

这是我的解决方案。无论如何,谢谢