Get an attribute of a dom node

后端 未结 2 1724
一个人的身影
一个人的身影 2021-02-06 21:03

I am trying to get an attribute of an xml node example:



I want to grab the name attribute of the car nod

相关标签:
2条回答
  • 2021-02-06 21:27

    you can do it without using elements, like this:

    //HtmlTag represents any arbitrary node that you are trying to get its "car" attribute 
    
    if("HtmlTag".equals(node.getNodeName()))
     String nodeContent=node.getAttributes().getNamedItem("car").getNodeValue()
    
    0 讨论(0)
  • 2021-02-06 21:33

    Your node is an Element so you just have to

    Element e = (Element)node;
    String name = e.getAttribute("name");
    
    0 讨论(0)
提交回复
热议问题