473,770 Members | 5,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

doc.getElementB yId()

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.parse rs.*;
import org.w3c.dom.*;
import org.xml.sax.SAX Exception;
import java.io.*;

public class prova
{
public static void main (String [] args)
{
try
{
DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance();
DocumentBuilder db = dbf.newDocument Builder();

Document doc = db.parse("http://localhost:8080/XML/prova.xml");

System.out.prin tln(doc.getElem entById("A1"));

}
catch (SAXException e)
{
e.printStackTra ce();
}

catch (IOException e)
{

e.printStackTra ce();
}

catch (ParserConfigur ationException e)
{
e.printStackTra ce();
}
}
}

output:
null

why it gives back null and not the node to me with the A1 code?

thanks

Mar 29 '07 #1
6 4203
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...@w3develop ment.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...@yaho o.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
2706
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 working, but it only worked for IE. You can see a working version here: http://www.publicpen.com/designer/mcControlPanel.php username: designer password: designer123 However, I've tried to rewrite this so it would work in all browsers,
12
3944
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 both single quotes and no single quotes, but it doesn't work either way. What am I doing wrong? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById('weblogs').style.visibility='hidden';
4
5482
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) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
7
5995
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 contraction follows at the bottom of my message here. This following line is a big part of my hang-up: document.getElementById('m1').style.display='none';
3
9274
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 work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
1
36531
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 and sets the value of a label (lblTotal) to the sum of the three textbox values. The form is in a content place holder. I've added the following block of code in my form load.
4
2645
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 iframe's src property. Being that IE does not follow standard and considers an id, name, etc as a qualifying identifier for the document.getElementById object, I double checked to make sure that there's only one instance of id = "servif" and I never use...
13
4956
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 internet. When I run Firebug on it, it says: document.getElementById("TICKER") has no properties TICKER_CONTENT = document.getElementById("TICKER").innerHTML; Here is the complete script:
5
5772
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 select box based on the user selected option of the first select box. It works fine in Mozilla but IE7 still shows all the optgroups in the second select box. The idea is to show the appropriate list of states based on what country a user selects...
1
2238
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 script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a hand. Thanks!!
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.