Is XPath much more efficient as compared to DOM and SAX?

前端 未结 5 864
再見小時候
再見小時候 2020-12-07 00:20

I need to parse an xml string and find values of specific text nodes, attribute values etc. I\'m doing this in javascript and was using the DOMParser class for the same. Lat

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 00:57

    SAX is a top-down parser and allows serial access to a XML document, and works well for read only access. DOM on the other hand is more robust - it reads the entire XML document into a tree, and is very efficient when you want to alter, add, remove data in that XML tree. XPath is useful when you only need a couple of values from the XML document, and you know where to find them (you know the path of the data, /root/item/challange/text).

    SAX: Time efficient when iterating through the document, gives a single pass for every iteration

    DOM: Flexible/performance, gives you more ways to work your data

    XPath: Time efficient when you only need to read a couple of values

提交回复
热议问题