B
Bryan
Hi there,
I ran into a kind of strange behavior of Java code. Maybe the reason
is obvious but I cannot figure it out ...
Suppose I have a xml file and from the field "<footag>bar
text</footag>" I simply want to extract "bar text". The following is
my code:
/**************************/
import org.w3c.dom.*;
..
..
..
String text;
Node textFieldNode;
..
..
.. //textFieldNode now points to the field.
//code A:
NodeList myLs = textFieldNode.getChildNodes();
for (int ii = 0; ii < myLs.getLength(); ii++) {
if (myLs.item(ii) instanceof Text)
text = myLs.item(ii).getNodeValue();
}
//code B:
text=textFieldNode.toString().replaceAll("<[/]*"+"footag"+">","");
..
..
..
/**********end of code********/
The problem is: Both code A and B generate the right result ("bar
text") when I test it. But when I include this class into a .jar file
and try to call it from within another package, code A generates,
still, the right result but code B assigns "[footage: null]" to text.
Just keen to know why the code works so differently.
Thanks in advance!
Regards,
Bryan
I ran into a kind of strange behavior of Java code. Maybe the reason
is obvious but I cannot figure it out ...
Suppose I have a xml file and from the field "<footag>bar
text</footag>" I simply want to extract "bar text". The following is
my code:
/**************************/
import org.w3c.dom.*;
..
..
..
String text;
Node textFieldNode;
..
..
.. //textFieldNode now points to the field.
//code A:
NodeList myLs = textFieldNode.getChildNodes();
for (int ii = 0; ii < myLs.getLength(); ii++) {
if (myLs.item(ii) instanceof Text)
text = myLs.item(ii).getNodeValue();
}
//code B:
text=textFieldNode.toString().replaceAll("<[/]*"+"footag"+">","");
..
..
..
/**********end of code********/
The problem is: Both code A and B generate the right result ("bar
text") when I test it. But when I include this class into a .jar file
and try to call it from within another package, code A generates,
still, the right result but code B assigns "[footage: null]" to text.
Just keen to know why the code works so differently.
Thanks in advance!
Regards,
Bryan