0

I have method:

 private static void print(NodeList nodeList) {

    for (int i = 0; i < nodeList.getLength(); i++) {
        Node t = nodeList.item(i);

        if (t.getNodeType() == Node.ELEMENT_NODE) {
            System.out.println("node: " + t.getNodeName());
            System.out.println("values " + t.getTextContent());
            System.out.println("------------------------------");
        }



        if (doc.hasChildNodes()) {
            print(t.getChildNodes());
        }
    }

}

It displays the contents of the xml document:

<Card>
        <Thema>people</Thema>
        <Type sent="true">advertising</Type>
        <Country>India</Country>
        <Year>1966</Year>
        <Authors><Author>Julia</Author></Authors>
        <Valuable>historical</Valuable>
    </Card>

but does not show the value of the attribute in the node "sent". How can I modify it? Thanks!

1 Answers1

0

Use the method getAttributes to get the list of attributes of a node:

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56