0

私はXMLにかなり慣れていないので、VBを使用して以下のファイルを解析するのに問題があります. 私がやりたいことは、ファイルの最後のタグに移動し、ノードを<SESSION>ループして値を取得することです。<IMAGE>

<?xml version="1.0" encoding="UTF-8"?>
<MIFORMS_EXPORT>
<SESSION FORM_ID="209688" CID="" ID="HAKKI-LAPTOP_634995474247656192">
    <FIELD NAME="A001DATE_M" />
    <FIELD NAME="A002" />
    <FIELD NAME="A003" />
    <FIELD NAME="A004" />
    <IMAGE NAME="P1" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-0-03222013-111042768-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P2" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-1-03222013-111042783-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P3" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-2-03222013-111042799-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P4" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-3-03222013-111042814-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P5" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-4-03222013-111042830-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P6" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-5-03222013-111042846-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P7" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-6-03222013-111042846-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P8" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-7-03222013-111042861-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P9" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-8-03222013-111042877-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P10" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-9-03222013-111042892-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
    <IMAGE NAME="P11" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-10-03222013-111042892-HAKKI-LAPTOP_634995474247656192.png</IMAGE>
  </SESSION>
  <SESSION FORM_ID="209688" CID="" ID="HAKKI-LAPTOP_634995479807027960">
    <FIELD NAME="A001DATE_M" />
    <FIELD NAME="A002" />
    <FIELD NAME="A003" />
    <FIELD NAME="A004" />
    <IMAGE NAME="P1" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-0-03222013-111944041-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P2" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-1-03222013-111944056-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P3" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-2-03222013-111944072-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P4" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-3-03222013-111944088-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P5" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-4-03222013-111944103-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P6" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-5-03222013-111944119-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P7" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-6-03222013-111944134-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P8" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-7-03222013-111944134-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P9" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-8-03222013-111944150-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P10" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-9-03222013-111944166-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
    <IMAGE NAME="P11" TYPE="PAGE" FORMAT="image/png" RESOLUTION="28.35" DEPTH="24">C:\wamp\www\Kapture.web\ClientBin\metis\images\209688-10-03222013-111944212-HAKKI-LAPTOP_634995479807027960.png</IMAGE>
  </SESSION>
</MIFORMS_EXPORT>

私はここまで持っています:

'TASK: Get the pen image PNG name
    'Get the total Session count in XML
    Dim penImageRaw As Int32 = doc.GetElementsByTagName("SESSION").Count            
    For startValue = 0 To penImageRaw
        i+=1
    Next

    'Grab the last session element
    Dim test As XmlNode = doc.GetElementsByTagName("SESSION").Item(i)

助けてくれてありがとう。

4

2 に答える 2

0

こんな感じでいかがですか?

'TASK: Get the pen image PNG name

'Get the total Session count in XML
Dim penImageRaw As Int32 = doc.GetElementsByTagName("SESSION").Count

If penImageRaw > 0 Then
  'Grab the last session element (Last one is count-1)
  Dim test As XmlNode = doc.GetElementsByTagName("SESSION").Item(penImageRaw-1)
  '
  'Now find IMAGE nodes in this SESSION node here
  '
Else
  'No session nodes found
End if
于 2013-03-22T11:51:19.757 に答える
0

解決しました。私を正しい方向に向けてくれたザフに感謝します。Google 社員の皆さん、最終結果は次のとおりです。

    Dim penImageRaw As Int32 = doc.GetElementsByTagName("SESSION").Count

If penImageRaw > 0 Then
  Dim test As XmlNode = doc.GetElementsByTagName("SESSION").Item(penImageRaw-1)
  Dim list As XmlNodeList = test.ChildNodes

For Each node As XmlNode In list
    If String.Equals(node.Name, "IMAGE")

    Dim wtf As String = node.FirstChild.Value

    MsgBox(wtf)
End If
    Next

Else
  MsgBox("No Session nodes found")
End If
于 2013-03-23T00:47:44.143 に答える