請教高手,解析巢狀XMl和建立多位陣列

princearthas發表於2005-05-23
我想解析這麼一個XML檔案,因為專案用的struts,所以很想用digester來解析,不過它的資料太少了,高手們有什麼建議嗎?

<?xml version="1.0" encoding="GB2312"?>
<tree>
  <father img="folder.gif" a="processAction.do?value=folder" name="folder">
    <father img="folder.gif" a="processAction.do?value=folder" name="folder">
      <child img="jpg.gif" a="processAction.do?value=jpg" name="jpg" />
      <child img="png.gif" a="processAction.do?value=png" name="png.gif" />
      <child img="bmp.gif" a="processAction.do?value=bmp" name="bmp.gif" />
      <father img="folder.gif" a="processAction.do?value=folder" name="folder">
        <child img="png.gif" a="processAction.do?value=png" name="png.gif" />
        <child img="bmp.gif" a="processAction.do?value=bmp" name="bmp.gif" />
      </father>
    </father>
    <child img="folder.gif" a="processAction.do?value=folder" name="folder" />
  </father>
</tree>

另外就是我想在java中儲存類似這樣的內容,請問如何儲存比較好?

Array
(
    [ul] => Array
        (
            [property] => Array
                (
                    [img] => folder.gif
                    [a] => processAction.do?value=folder
                    [name] => folder
                )
            [li] => Array
                (
                    [img] => gif.gif
                    [a] => processAction.do?value=gif
                    [name] => gif
                )
            [jpg] => Array
                (
                    [img] => jpg.gif
                    [a] => processAction.do?value=jpg
                    [name] => jpg
                )
            [bmp] => Array
                (
                    [img] => bmp.gif
                    [a] => processAction.do?value=bmp
                    [name] => bmp
                )
            [png] => Array
                (
                    [img] => png.gif
                    [a] => processAction.do?value=png
                    [name] => png
                )
        )
    [li] => Array
        (
            [img] => folder.gif
            [a] => processAction.do?value=folder
            [name] => folder
        )
)
<p class="indent">

相關文章