XML child node attribute value

前端 未结 3 898
孤独总比滥情好
孤独总比滥情好 2020-12-16 08:05

I\'m trying to read xml file, ex :


    FEED TITLE
    5467sdad98787ad3149878sasda
    

        
3条回答
  •  太阳男子
    2020-12-16 08:36

    Use Element.getAttribute and Element.setAttribute

    In your example, ((Node) content.item(0)).getFirstChild().getAttributes(). Assuming that content is a typo, and you mean contento, getFirstChild is correctly returning NULL as contento has no children. Try: ((Node) contento.item(0)).getAttributes() instead.

    Another issue is that by using getFirstChild and getChildNodes()[0] without checking the return value, you are running the risk of picking up child text nodes, instead of the element you want.

提交回复
热议问题