我已經使用 xml.UnMarshal 方法來獲取 struct 對象,但它有其自身的局限性。我需要一種方法,可以在不指定確切 xpath 的情況下獲取節點內特定類型的所有后代。例如,我有以下格式的 xml 數據:<content> <p>this is content area</p> <animal> <p>This id dog</p> <dog> <p>tommy</p> </dog> </animal> <birds> <p>this is birds</p> <p>this is birds</p> </birds> <animal> <p>this is animals</p> </animal></content>現在我想遍歷上面的 xml 并按順序處理每個節點及其子節點。問題是這種結構不是固定的,元素的順序可能會改變。所以我需要一種方法,以便我可以像While(Content.nextnode()){ switch(type of node) { //Process the node or traverse the child node deeper }}
- 3 回答
- 0 關注
- 278 瀏覽
添加回答
舉報
0/150
提交
取消