请教高手,解析嵌套XMl和创建多位数组

05-05-23 princearthas
我想解析这么一个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>

banq
2005-05-23 08:57
没有必要用digest,普通Dom方法即可,参考OSworkflow源码,或使用dom4j、Jdom都可以,你后面的例子我感觉使用Castor不错,每个单元是一个对象,XML实际是一个对象列表。

hgwnet
2005-05-23 12:52
用xpp的mxpp3,xml解析速度超一流。

princearthas
2005-05-24 13:52
大汗中,用了dom4j,看了不少文档,可是居然没有发现遍历xml的方法,不知道哪位高人有这方面的代码?

猜你喜欢