DOM Problem with getNodeValue()

P

Peter Chatterton

DOM Problem with getNodeValue()

I parsed an xml file starting with:
<?xml version="1.0" encoding="UTF-8"?>

Later, when I'm serializing the document
(after Brett McLaughlin's book),
and call getNodeValue(), I get:
version = '1.0' encoding = 'UTF-8'

If I write this out it gives errors
when I read it back in and parse it.

If I change the single quotes to double,
while serializing, it works okay.

Is this a bug in DOM?

Thanks,
Peter.

import org.w3c.dom.Document;
java version "1.4.2"
Jikes 1.16 on Textpad under win2K
 
P

Peter Chatterton

For which Node are you calling getNodeValue() to get that result?It's hard to tell because it's not my code and it uses recursion.
But it's in a switch statement as follows:
switch( node.getNodeType() )
case Node.PROCESSING_INSTRUCTION_NODE

Anyway, it's a very small file and there's only one line like it.

BTW line 2 is:
<Agency xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
agencyName="nameOfAgency">

Peter.
 
W

William Brogden

Peter Chatterton said:
DOM Problem with getNodeValue()

I parsed an xml file starting with:
<?xml version="1.0" encoding="UTF-8"?>

Later, when I'm serializing the document
(after Brett McLaughlin's book),
and call getNodeValue(), I get:
version = '1.0' encoding = 'UTF-8'

If I write this out it gives errors
when I read it back in and parse it.

If I change the single quotes to double,
while serializing, it works okay.

Is this a bug in DOM?

Thanks,
Peter.

import org.w3c.dom.Document;
java version "1.4.2"
Jikes 1.16 on Textpad under win2K

For which Node are you calling getNodeValue() to get that result?
 
P

Peter Chatterton

OK, that makes sense - the contents of the whole Processing Instruction is
what
you are supposed to get. Either single or double quotes should be legal.
What error do you get when you write it out and then try to parse it?
I'm glad it makes sense to you, because I'm thoroughly confused.

I think these are the error msg's:
<xml version = '1.0' encoding = 'UTF-8'?>
XML-0190: (Fatal Error) Whitespace required. :
XML-0201: (Fatal Error) Expected name instead of ?. :
XML-0122: (Fatal Error) '=' missing in attribute. :
XML-0125: (Fatal Error) Attribute value should start with quote.
formatParseError,

I've looked in the book and the <xml version line is supposed to be
hard-coded
with the DOCUMENT_NODE. I took it out because I was getting another one
generated by the PI node -- which is what is confusing me.
Anyway, I don't need to process PROCESSING_INSTRUCTION_NODE
as I don't have any, I only have a few types.

Here's an example of my xml:
<oneConsultant personName="Roman Pelts">
<timeLine start="2002-11-21" end="2003-12-11"/>
<memberList>
<projectName projectName="ibmJava1"/>
</memberList>
<activity type="vacation" start="2002-1-1" end="2002-12-31"/>
</oneConsultant>
and I also have <oneProject> with a similar structure.

So I'm wondering if I need recursion at all?

On the other hand, do I need to code my own serialization at all?

Thanks again and any suggestions would be appreciated,
Peter.
 
W

William Brogden

Peter Chatterton said:
It's hard to tell because it's not my code and it uses recursion.
But it's in a switch statement as follows:
switch( node.getNodeType() )
case Node.PROCESSING_INSTRUCTION_NODE

Anyway, it's a very small file and there's only one line like it.

OK, that makes sense - the contents of the whole Processing Instruction is
what
you are supposed to get. Either single or double quotes should be legal.
What
error do you get when you write it out and then try to parse it?
 
P

Peter Chatterton

UPDATE

I've hard-coded

<?xml version=\"1.0\" encoding=\"UTF-8\"?>

in the DOCUMENT_NODE and it works okay.


I'd prefer to get the API to do it for me,
but can't find any reference to serialization.
Any ideas?

Thanks,
Peter.
 
R

Rick Genter

In your original example, you didn't have the leading question mark: you
wrote

<xml version='1.0' encoding='UTF-8'?>

instead of

<?xml version='1.0' encoding='UTF-8'?>

Could that be the problem?
 
W

William Brogden

Peter Chatterton said:
is
I'm glad it makes sense to you, because I'm thoroughly confused.

I think these are the error msg's:
<xml version = '1.0' encoding = 'UTF-8'?>
XML-0190: (Fatal Error) Whitespace required. :
XML-0201: (Fatal Error) Expected name instead of ?. :
XML-0122: (Fatal Error) '=' missing in attribute. :
XML-0125: (Fatal Error) Attribute value should start with quote.
formatParseError,

I can't see why it is not accepting the single quote instead of double
quote.
The simplest thing to do would be to stick double quotes back in and not
worry about it.
 
P

Peter Chatterton

Rick Genter said:
In your original example, you didn't have the leading question mark: you
wrote
<xml version='1.0' encoding='UTF-8'?>
instead of
<?xml version='1.0' encoding='UTF-8'?>
Could that be the problem?
Hey, that's a good one!

That was the PI processing doing its stuff,
now that I'm doing it manually it's okay.

Thanks,
Peter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,089
Latest member
Ketologenic

Latest Threads

Top