I have a problem using the method getElementById:
This is my code:
dtd file: prova.dtd
<!ELEMENT utente (nome, password)>
hml file: prova.xml
<?xml version="1.0"?>
<!DOCTYPE lista>
<lista>
<utente id = 'A1'>
<nomeA1 </nome>
<passwordpp </password>
</utente>
<utente id = 'A2'>
<nomeA2 </nome>
<passwordpp </password>
</utente>
</lista>
java file: prova.java
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.*;
public class prova
{
public static void main (String [] args)
{
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("http://localhost:8080/XML/prova.xml");
System.out.println(doc.getElementById("A1"));
}
catch (SAXException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
}
}
output:
null
why it gives back null and not the node to me with the A1 code?
thanks