473,491 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML Parsing with Java.

dmjpro
2,476 Top Contributor
Hi Experts.
I have a problem with XML parsing.
Please Help!

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <XML>
  3. <Debasis>some_value</Debasis>
  4. <DmjPro>some_another_value</DmjPro>
  5. <!--Some Comment-->
  6. <!--Some another comment-->
  7. <Saswati title="Mahapatra" disignation="project_member"></Saswati>
  8. <DebMou ID="my_id">some_value_saswati</DebMou>
  9. </XML>
  10.  
And my Java Code is:
Expand|Select|Wrap|Line Numbers
  1. Element el=doc.getElementById("my_id");
  2. System.out.println("DebMou_Node_value: "+el);
  3.  
Now the second line prints Null.
Why?
Please help.
Is there any wrong format with XML?


Kind regards,
Dmjpro.
Sep 4 '07 #1
10 2963
r035198x
13,262 MVP
Hi Experts.
I have a problem with XML parsing.
Please Help!

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <XML>
  3. <Debasis>some_value</Debasis>
  4. <DmjPro>some_another_value</DmjPro>
  5. <!--Some Comment-->
  6. <!--Some another comment-->
  7. <Saswati title="Mahapatra" disignation="project_member"></Saswati>
  8. <DebMou ID="my_id">some_value_saswati</DebMou>
  9. </XML>
  10.  
And my Java Code is:
Expand|Select|Wrap|Line Numbers
  1. Element el=doc.getElementById("my_id");
  2. System.out.println("DebMou_Node_value: "+el);
  3.  
Now the second line prints Null.
Why?
Please help.
Is there any wrong format with XML?


Kind regards,
Dmjpro.
Can you post the full code you used for this?
Sep 4 '07 #2
dmjpro
2,476 Top Contributor
Can you post the full code you used for this?
This is my full Java Code.

Expand|Select|Wrap|Line Numbers
  1. DocumentBuilder d = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  2. Document doc = d.parse(new File("c:/Test.xml"));
  3. Element el=doc.getElementById("my_id");
  4. System.out.println("DebMou_Node_value: "+el);
  5.  
Now I think you will be able to solve my problem?
And Thanks for reply me.

Kind regards,
Dmjpro.
Sep 4 '07 #3
r035198x
13,262 MVP
This is my full Java Code.

Expand|Select|Wrap|Line Numbers
  1. DocumentBuilder d = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  2. Document doc = d.parse(new File("c:/Test.xml"));
  3. Element el=doc.getElementById("my_id");
  4. System.out.println("DebMou_Node_value: "+el);
  5.  
Now I think you will be able to solve my problem?
And Thanks for reply me.

Kind regards,
Dmjpro.
Use getelementByTagName to get the required elements.

See the docs for what's required for you to be able to use getElementByID
Sep 4 '07 #4
dmjpro
2,476 Top Contributor
Use getelementByTagName to get the required elements.

See the docs for what's required for you to be able to use getElementByID
I already had a look at those Docs.
But I could not find any Error in XML file.
That's why i come here.
But I want to know what is the problem with getElementById()?
I know it can be solved using getElementsbyTagName().
Please help to solve this problem using getElementById().

Kind regards,
Dmjpro.
Sep 4 '07 #5
r035198x
13,262 MVP
I already had a look at those Docs.
But I could not find any Error in XML file.
That's why i come here.
But I want to know what is the problem with getElementById()?
I know it can be solved using getElementsbyTagName().
Please help to solve this problem using getElementById().

Kind regards,
Dmjpro.
Did you read the docs entry for getElementById like I said? It tells you why you got the value as null and when you can use it.
Sep 4 '07 #6
dmjpro
2,476 Top Contributor
Did you read the docs entry for getElementById like I said? It tells you why you got the value as null and when you can use it.
Could you help me please?
I can't get what's the Error with my XML file.
Please help.

Kind regards,
Dmjpro.
Sep 4 '07 #7
r035198x
13,262 MVP
Could you help me please?
I can't get what's the Error with my XML file.
Please help.

Kind regards,
Dmjpro.
From the docs that you claim to have read
" ... 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. "
Sep 4 '07 #8
JosAH
11,448 Recognized Expert MVP
From the docs that you claim to have read
" ... 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. "
Ah! reading! That ancient lost artform; this is the copy/paste age, people can't
read anymore. Reading wastes time; better ask vague questions everywhere
and hope that someone supplies you with the stuff to be copied and pasted.
Let other's waste their time; who cares.

If it works; fine; who cares *why* it works anyway? If it doesn't, come back and
complain; if no new copyable/pasteable replies follow; so be it. If they do: rinse
and repeat. What a beautiful 'information' society we live in.

I plea for the following software development methodology: there are two buildings:
one luxury building with all the fun and luxury but *no* development environments
there. Internet connections: yes; comfy chairs: yes; an abundance of coffee etc.:
yes; but no compilers, no debuggers, no nothing of the sort. A lot of pencils and
paper: yes.

When the software has been designed one has to migrate to that other building
where a lot of compilers, fast computers, debuggers etc. are available. But no
coffee, no internet connections, no comfy chairs, no nothing.

One is not allowed to leave that building until the designed software has been
implemented. That should teach those lazy analphabetic bums to read their own
notes, to read what those compilers have to tell them; to read runtime error
messages etc. Otherwise they're never allowed to leave that boring second building.

kind regards,

Jos
Sep 4 '07 #9
r035198x
13,262 MVP
Ah! reading! That ancient lost artform; this is the copy/paste age, people can't
read anymore. Reading wastes time; better ask vague questions everywhere
and hope that someone supplies you with the stuff to be copied and pasted.
Let other's waste their time; who cares.

If it works; fine; who cares *why* it works anyway? If it doesn't, come back and
complain; if no new copyable/pasteable replies follow; so be it. If they do: rinse
and repeat. What a beautiful 'information' society we live in.

I plea for the following software development methodology: there are two buildings:
one luxury building with all the fun and luxury but *no* development environments
there. Internet connections: yes; comfy chairs: yes; an abundance of coffee etc.:
yes; but no compilers, no debuggers, no nothing of the sort. A lot of pencils and
paper: yes.

When the software has been designed one has to migrate to that other building
where a lot of compilers, fast computers, debuggers etc. are available. But no
coffee, no internet connections, no comfy chairs, no nothing.

One is not allowed to leave that building until the designed software has been
implemented. That should teach those lazy analphabetic bums to read their own
notes, to read what those compilers have to tell them; to read runtime error
messages etc. Otherwise they're never allowed to leave that boring second building.

kind regards,

Jos
Which building has the better pay?
Sep 5 '07 #10
dmjpro
2,476 Top Contributor
Ah! reading! That ancient lost artform; this is the copy/paste age, people can't
read anymore. Reading wastes time; better ask vague questions everywhere
and hope that someone supplies you with the stuff to be copied and pasted.
Let other's waste their time; who cares.

If it works; fine; who cares *why* it works anyway? If it doesn't, come back and
complain; if no new copyable/pasteable replies follow; so be it. If they do: rinse
and repeat. What a beautiful 'information' society we live in.

I plea for the following software development methodology: there are two buildings:
one luxury building with all the fun and luxury but *no* development environments
there. Internet connections: yes; comfy chairs: yes; an abundance of coffee etc.:
yes; but no compilers, no debuggers, no nothing of the sort. A lot of pencils and
paper: yes.

When the software has been designed one has to migrate to that other building
where a lot of compilers, fast computers, debuggers etc. are available. But no
coffee, no internet connections, no comfy chairs, no nothing.

One is not allowed to leave that building until the designed software has been
implemented. That should teach those lazy analphabetic bums to read their own
notes, to read what those compilers have to tell them; to read runtime error
messages etc. Otherwise they're never allowed to leave that boring second building.

kind regards,

Jos
Again impressive.
Really I am sorry Jos.
That I didn't read carefully what rox told me to read.
But I saw he just made bold the main line nothing changes was there then I understood.
Anyway, thanks for saying thing ... I always prefer the second building.
The R&D building.
I think you did a lot of hard works.
That's you mentality is such ..... Different.
Anyway, Best of Luck with your life whatever you are doing.

Kind regards,
Dmjpro
Sep 5 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
4240
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards...
14
2614
by: Viktor Rosenfeld | last post by:
Hi, I need to create a parser for a Python project, and I'd like to use process kinda like lex/yacc. I've looked at various parsing packages online, but didn't find anything useful for me: -...
0
1537
by: Naren | last post by:
I have an XML like the one below. I am using SAX parsing and I need to get the information between the tags of the Email element. First i try to access the content and print it out and it gives...
4
7219
by: Pushya | last post by:
Hello - I am trying to parse a .XSD file to obtain information about element name and type in the file. I have been trying to find some kind of documentation for Schema Parsing. All I come...
2
3913
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
0
4099
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
3
2594
by: John Doe | last post by:
I've been doing some reading/research on parsing simple configuration files through C, and have heard various opinions on the matter. I'd like to solicit some opinions and design criteria (as well...
3
11924
by: spittinfire | last post by:
-------------------------------------------------------------------------------- I am trying to correct the errors on an assignment that has already been graded because I have to now modify it and...
5
7701
by: PatlaDJ | last post by:
Java SAX parser, please need a clue how to get the raw XML code of the currently parsing event... needed for logging, debugging purposes. Here's and example, letting me clarify exactly what i...
1
4348
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7154
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
7190
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...
1
6858
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
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.