I am having a problem with a method in the java org.w3c.dom package. To be specific :

getElementById(String elementID)

The problem is basically this if I create an element using the dodument.createElement() method and then set an attribute "id" using element_obj.setAttribute("id","Index") (this is how I have seen it done in every example I have been able to find using google), once I have added this to the document using document.appendChild(element_obj) if I use document.getElementById("Index") I get a null pointer instead of a reference to the node.

I will include a short section of code at the end. I have tried having the attribute name as "id", "ID" and "Id" none of these work. I have been able to find a short note in the API documentation reading

"Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null."

But I have not been able to find any information on how I can do this. I anyone out there knows how, a quick point in the right direction would be greatly apreciated.

<code snippet>
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
//This document only has one tag initially
Element root = document.createElement("Index");


Element testID = document.getElementById("Index");
if(testID == null){
System.out.println("Get by ID did not work");
} else { System.out.println(testID.toString() +" Sucess!!!\n"); }
</code snippet>


ps sorry if this a bit lengthy, but without all the info it would not be clear.