1

次の 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">ですSLM_CekNonNegativeか?

以下は私がこれまでに持っているコードです:

string pathasr = @"D:\HARPITNAS\dari mbak julia\logs\123456789-2012-09-30-BSMS10.xml-assertions2.xml";
List<string> msg = new List<string>();
XmlDocument doc = new XmlDocument();
doc.Load(pathasr);

foreach (XmlNode node in doc.DocumentElement)
{
     string thevaluethatiwantvariable = string.Empty;  
     thevaluethatiwantvariable  = ? ;

     if (node.LastChild.HasChildNodes == true)
     {
          string count = node.LastChild.ChildNodes.Count.ToString();
          foreach (XmlNode y in node.LastChild.ChildNodes)
          {
               string masg = y.InnerXml;
               msg.Add(masg);
          }
     }
}

このコードは、私が望む値を取得しません。デバッグすると、正しい値が得られないことがわかります。私が望む値を取得することは可能ですか?

4

2 に答える 2

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

詳細については、 http ://www.w3schools.com/xpath/xpath_syntax.aspをご覧ください。

于 2013-03-15T13:53:04.010 に答える
2

XPath がないと、次のようになります。

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

そして、いかなる種類のループも必要ありません。

于 2013-03-15T14:00:17.443 に答える