Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getElementById

1 view
Skip to first unread message

Paolo

unread,
Mar 29, 2007, 4:21:22 AM3/29/07
to
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'>
<nome> A1 </nome>
<password> pp </password>
</utente>

<utente id = 'A2'>
<nome> A2 </nome>
<password> pp </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

0 new messages