按属性获取元素过滤

时间:2013-03-15 13:47:53

标签: c# xml xsd

我有以下XML:

    <?xml version="1.0" encoding="utf-8"?>
<assertions>
    <assertion id="SLM_CekNonNegative">
        <satisfied count="36"/>
        <unsatisfied count="4">
            <message xml:lang="id">(Record ID = ID_2) SLM: Jumlah bulan lalu, jumlah bulan laporan, jumlah hari tunggakan, dan jumlah tunggakan pokok tidak boleh kosong dan harus diisi >= 0</message>
            <message xml:lang="id">(Record ID = ID_2) SLM: Jumlah bulan lalu, jumlah bulan laporan, jumlah hari tunggakan, dan jumlah tunggakan pokok tidak boleh kosong dan harus diisi >= 0</message>
            <message xml:lang="id">(Record ID = ID_2) SLM: Jumlah bulan lalu, jumlah bulan laporan, jumlah hari tunggakan, dan jumlah tunggakan pokok tidak boleh kosong dan harus diisi >= 0</message>
            <message xml:lang="id">(Record ID = ID_2) SLM: Jumlah bulan lalu, jumlah bulan laporan, jumlah hari tunggakan, dan jumlah tunggakan pokok tidak boleh kosong dan harus diisi >= 0</message>
        </unsatisfied>
    </assertion>
    <assertion id="Base_CekJangkaWaktuMulaiLebihMudaJatuhTempo">
        <satisfied count="10"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="SLM_CekJumlahBulanKrgDrNilaiKontrak">
        <satisfied count="10"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekTanggalLebihMudaTanggalPelaporan">
        <satisfied count="10"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="SLM_CekNilaiKontrak">
        <satisfied count="2"/>
        <unsatisfied count="8">
            <message xml:lang="id">(Record ID = ID_10) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_9) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_8) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_7) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_6) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_5) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_2) Nilai kontrak harus > 0</message>
            <message xml:lang="id">(Record ID = ID_1) Nilai kontrak harus > 0</message>
        </unsatisfied>
    </assertion>
    <assertion id="SLM_CekGolNasabah">
        <satisfied count="9"/>
        <unsatisfied count="1">
            <message xml:lang="id">(Record ID = ID_2) Golongan nasabah tidak boleh diisi sandi bank pelapor sendiri</message>
        </unsatisfied>
    </assertion>
    <assertion id="BS-IF_CekSLMVls">
        <satisfied count="1"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="BS-IF_CekSLMIDR">
        <satisfied count="1"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekHubunganTidakTerkaitStatusLainnya">
        <satisfied count="8"/>
        <unsatisfied count="2">
            <message xml:lang="id">(Record ID = ID_3) Base: "Status hubungan dengan Bank" harus terisi sandi 9 jika Kolom "Klasifikasi Nasabah - Hubungan dengan bank" terisi sandi 2</message>
            <message xml:lang="id">(Record ID = ID_2) Base: "Status hubungan dengan Bank" harus terisi sandi 9 jika Kolom "Klasifikasi Nasabah - Hubungan dengan bank" terisi sandi 2</message>
        </unsatisfied>
    </assertion>
    <assertion id="Base_CekLembagaNilaiPemeringkat">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekNeracaMinNol">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekNilaiAgunanMinNol">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekPersentaseMaksimal100">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekLembaga-Tanggal-NilaiPeringkat">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekIdentifier">
        <satisfied count="1"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekNomor-JumlahAgunan">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekEligibilityJenisAgunan">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_CekSifat-GolonganPenerbitAgunan">
        <satisfied count="0"/>
        <unsatisfied count="0"/>
    </assertion>
    <assertion id="Base_cekPeriod">
        <satisfied count="1"/>
        <unsatisfied count="0"/>
    </assertion>
</assertions>

如何获得<assertion id="SLM_CekNonNegative">的{​​{1}}的价值?

以下是我到目前为止的代码:

SLM_CekNonNegative

此代码未获得我想要的值。当我调试它时,我可以看到它没有得到正确的值。是否有可能获得我想要的价值?

2 个答案:

答案 0 :(得分:4)

thevaluethatiwantvariable  = doc.DocumentElement.SelectSingleNode("//assertion[@name = 'id']/@value").Value;

欲了解更多信息: http://www.w3schools.com/xpath/xpath_syntax.asp

答案 1 :(得分:2)

没有XPath就是这样:

string theValue = doc.DocumentElement["assertion"].Attributes["id"].Value;

并且不需要任何类型的循环。