先搞清楚sax是怎么解析xml的吧.

解决方案 »

  1.   

    If you do insist to use SAX, more work will be done. First of all we all know that SAX parser will parse the XML for you so that it can trigger some events which your handler are listening. That's fine but for your demand, the result is not fine. You can get to the element 'request' using your handler, but the next step is up to you. You should do some serialization job to save all the content under the 'request'. For example, you meet 'request' first, then 'data', then 'abc', ... at last you met the end of 'request'. SAX has done the parsing job for you, but you need to assemble the parsed elements to string, just like this:"<" + data + ">" + "<" + abc + ">" ...That is the way you can get what you want. Or use DOM to reconstruct the child structure under the element 'request'. That's almost the same as I said, and the only difference is not using string plus but DOM constrution. 
      

  2.   

    agree hellking(信息孤岛)
    sax解析的时候并没有上下文的关系,它是事件触发的,每到一个节点就会触发事件,得不到它的子节点和父节点,只能用dom解决你的问题