473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

doc.getElementById()

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

Mar 29 '07 #1
6 4180
Paolo schrieb:
I have a problem using the method getElementById:
See the documentation for this method at
<http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-getElBId>:
Note: The DOM implementation must have information that says which attributes are of type ID. 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.
[...]
This is my code:

dtd file: prova.dtd

<!ELEMENT utente (nome, password)>
You did not define the id attribute to be of type ID.

--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Mar 29 '07 #2
On 29 Mar, 11:15, Johannes Koch <k...@w3development.dewrote:
Paolo schrieb:
I have a problem using the method getElementById:

See the documentation for this method at
<http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-...>:
Note: The DOM implementation must have information that says which attributes are of type ID. 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.

[...]
This is my code:
dtd file: prova.dtd
<!ELEMENT utente (nome, password)>

You did not define the id attribute to be of type ID.
I have not very understand what you have said to me.

I have corrected the in this mode:

<!ELEMENT utente (nome, password)>
<!ATTLIST utente ID ID #REQUIRED>

but the output of the java code retrun always null.

Mar 29 '07 #3
Paolo wrote:
I have corrected the in this mode:

<!ELEMENT utente (nome, password)>
<!ATTLIST utente ID ID #REQUIRED>

but the output of the java code retrun always null.
XML is case sensitive, if you have
<utente id = 'A1'>
then you need to define an attribute with name 'id' and not with name
'ID'. The type needs to be 'ID' however.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 29 '07 #4
Paolo schrieb:
I have corrected the in this mode:

<!ELEMENT utente (nome, password)>
<!ATTLIST utente ID ID #REQUIRED>
In the sample XML code you posted the attribute was named 'id' instead
of 'ID'. You need to declare an attribute 'id' to be of type ID.
Additionally you have to reference the document type definition from
within your XML by the system identifier (URI). You may also have to set
the document builder factory to 'validating', but I'm not sure if this
is necessary.

--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Mar 29 '07 #5
On 29 Mar, 14:12, Martin Honnen <mahotr...@yahoo.dewrote:
Paolo wrote:
I have corrected the in this mode:
<!ELEMENT utente (nome, password)>
<!ATTLIST utente ID ID #REQUIRED>
but the output of the java code retrun always null.

XML is case sensitive, if you have
<utente id = 'A1'>
then you need to define an attribute with name 'id' and not with name
'ID'. The type needs to be 'ID' however.
It was various because I was making some tests.

<?xml version="1.0"?>
<!DOCTYPE lista>

<lista>
<utente ID = "A1">
<nomeA1 </nome>
<passwordpp </password>
</utente>

<utente ID = "A2">
<nomeA2 </nome>
<passwordpp </password>
</utente>
</lista>

<!ELEMENT utente (nome, password)>
<!ATTLIST utente ID ID #REQUIRED>

but the output is: null

Mar 29 '07 #6
Paolo wrote:
<!DOCTYPE lista>
<!ELEMENT utente (nome, password)>
<!ATTLIST utente ID ID #REQUIRED>
You need to link to the DTD e.g.
<!DOCTYPE lista SYSTEM "lista.dtd">
where lista.dtd then contains the element and attribute definitions.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 29 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
7
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu. The code that seems to handle the expansion and...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
1
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
5
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
1
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.