Barbara Foute Nelong

Greenhorn
+ Follow
since Nov 30, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Barbara Foute Nelong

Thanks Bill! It really helped!
:-)
Hello everyone,
can anybody shed light on my problem?
I create an xml document with the ibm parser, I print the result to the console and I get:
<application>
<type>
<number/>
<kind/>
</type>
<client>
<demo>
<first_name/>
<last_name/>
<salutation/>
<age/>
<marital_status/>
</demo>
</client>
</application>
wich is exactly the data structure I want. I save it to a file.
Now I want to get the file, parse it and loop through the nodes to get to a specific node.
code:
NonValidatingTXDOMParser parser = new NonValidatingTXDOMParser();
parser.parse(new InputSource(xml));
doc = (com.ibm.xml.parser.TXDocument)parser.getDocument();
now I want to find the element "type" in my datastructure and visit its children:
for(Node node=doc.getDocumentElement().getFirstChild();
node!=null;
node.getNextSibling()){
if(node.getNodeName().equalsIgnoreCase("type")){.....}
I cannot get pass this point because the node.getNodeName always returns "#text".
A system.out.println(node) reveals that the parser see the element (that I have created as TXElement) as a TXtext...
Anybody knows why?
Any way around it?

[This message has been edited by Barbara Foute Nelong (edited July 08, 2001).]
Hello guys....help!
I am trying to go through an xml data structure to modify the values of certain nodes. I want to loop through the doc looking for a specified node and set its value, but all what I get is an infinite loop printing out #text instead of the node name because the node is a text node?!....what determine the types of nodes?
Here's my code...
Please somebody help me!!!
public String getDocument(String xml) {
com.ibm.xml.parser.TXDocument doc=null;
String document=null;
try{
NonValidatingTXDOMParser parser = new NonValidatingTXDOMParser();
parser.parse(new InputSource(xml));
doc = (com.ibm.xml.parser.TXDocument)parser.getDocument();

// LET'S MODIFY SOMETHING NOW
if(doc!=null){
String root=doc.getDocumentElement().getTagName();
if(root!=null){
System.out.println("root:" + root);
Node theNode=doc.getDocumentElement().getFirstChild();
System.out.println("child name:" + theNode.getNodeValue());

for(Node node=doc.getDocumentElement().getFirstChild(); node!=null;node.getNextSibling()){
System.out.println("node name:" + node.getNodeName());
if(node.getNodeName().equalsIgnoreCase("item")){
for(Node item=node.getFirstChild(); item!=null;item.getNextSibling()){
System.out.println("item name:" + item.getNodeName());
for(Node detail = item.getFirstChild(); detail!=null;detail.getNextSibling()){
if(detail.getNodeName().equalsIgnoreCase("model")){
detail.setNodeValue("MVC456");
}else if(detail.getNodeName().equalsIgnoreCase("Price")){
detail.setNodeValue("$450.00");
}else if(detail.getNodeName().equalsIgnoreCase("qty")){
detail.setNodeValue("10");
}else if(detail.getNodeName().equalsIgnoreCase("price_type")){
detail.setNodeValue("R");
} //end if
}
}
}
}
}
}

ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(stream);
doc.printWithFormat(pw);
document=stream.toString();

}catch(Throwable t){
System.out.println("Exception parsing");
t.printStackTrace();
System.out.println("message:" + t.getMessage());
}



return document;
}
Thank everyone. It's clear now.
:-)
sorry guys if I insist...I may seem a little dum. The mechanism of the adapter classes it's straightforward, the only thing that I do not get is why they are defined as ABSTRACT in the API. Null methods are not the same as abstract methods. I do not get what is abstract here.
Adapter classes provide "do nothing" implementation of all methods of Listener Interfaces (only the 7 that define multiple methods).
The API calls these classess ABSTRACT...why? I thought that extending an abstract class would entail providing implementation to all its methods (unless the subclass is abstract too) while the purpose of the Adapter classes is to offer the possibility of implementing only the method of interest.
Help!
Thanks everyone. I am OK now. It was a problem of the underlying OS...
I think answer 1 is fine.
The signature of a method is composed by its name and its parameter list (here DoubleValue(int a)). The compiler complains because it indeed sees two methods with the same signature.
Changing only the return value is not enough to overload a method. Changing its parameter list (with float in this case) would make the code compile.

Originally posted by Hina Mustafa:
hi,
There's a question from a mock exam..
Consider the following code and select the most appropriate statements.
Public class overL{
public int doubleValue(int a){}
public float doubleValue(int a){}
}

the correct answers given by the exam are
1-The code doesn't compile because the compiler sees two methods with the same signature.
2-The code can be made to compile by redefining the parameter for doubleVal() on line 7 to be "float a" instead of "int a".
I suspect that answer 1 is not correct instead of 'singnature' it should be 'parameter'.
Please someone assure me I'm right.
Thanx
Hina.


I tried and retried changing all the possible combinations of paths and classpaths to the jdk1.2.2\bin, to the jdk1.2.2\bin, to the jdk1.2.2\jre\bin.....I re-downloaded and reinstalled the whole jdk...big frustration!!!
what you mean by "add the 1 to the above result" in rule 3?
Thanks...I am confused
As stated before...it is a matter of terminology.
you can say
1.subclasses do not inherit private members of superclass (because a class can access all its member, the fact that it cannot access the private members of a superclass makes it look like those are not inherited)
or
2.subclasses inherit all instance fields\methods(NOT CONSTRUCTORS) of their superclass, but can only access those not declared private
HOWEVER
I agree with Ajith ALL members is too generic(it is inclusive of constructors) and the answer should be FALSE.
Thanks Jane. This is the code:
import java.awt.*;
import java.awt.event.*;
public class FrameTest extends Frame{

FrameTest(){
setSize(300,300);
Panel p = new Panel();
for (int i=0;i<4;i++){
Button b= new Button("Button #" + i);
p.add(b);
}
add(p,BorderLayout.NORTH);
addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
System.exit(0);}});

}

public static void main(String args[]){
FrameTest myFrame = new FrameTest();
myFrame.setVisible(true);
}

}
and this put a period to it. Thanks sheriff.
mhhhh, constructors are not inherited. Every class must define its own constructors. A subclass EXTENDS a superclass, which means that adds some data and\or behavior to the superclass'. The object that get instantiated (through the call to the constructor) has all the data of the superclass (implicit call to super()) and the new defined data.
To inherit a superclass constructor and use it as is, wold not make much sense because you will end up with an instance of the superclass, not and instance of the subclass.
No, I would say constructors are not inheridet, but the implementation of the class is inherited. An instance of a subclass contain a fully fledged instance of its superclass thanks to the implicit (or explicit) call to the superclass constructor.

Originally posted by Adrian Yan:
This is a theoretical question.
For example, constructors are not inherited by the subclasses. Private members are inherited, you just can't use them.
My question is: do you consider constructors members?


Well, if you do not override a method inherited from your superclass you go by its implementation as defined in the superclass.
However, wait() is declared final (final methods cannot be overridden), so you don't have a choice: all the subclasses of object (how wide is that!) inherit wait() and cannot do anything else that go by its implementation as defined in Object.
Cheers
Barb

Originally posted by Charley Wu:
The more I read, the more confused I am. I know that wait() is defined in Object, not in Thread. However, as Thread is derived from Object, a thread object should also has a wait() method. Is that right?