How to pass a returned value to a variable

I am a brand spanking new Java programmer.  I am using a SAX parser to Parse an XML file.  I need to make the element searched for a dynamic variable with the value pulled from another XML file.

  public void startElement(String namespaceURI,
                           String lName,
                           String qName,
                           Attributes attrs)
 throws SAXException
  {
      String eName = lName; // Set element name equal to local name
      if ("".equals(eName)) eName = qName;
      if (eName.equals("w:t")) <<<<<<< this value needs to be pulled from another XML file
      emit("<"+eName);
      nl();

I would like to use a new seperate class to do this in the interest of reusable code.  How do I call that outside class from the above code and pass the returned value. Also I am simply reusing the already created parser with a few modifications to do this, however it is written to pass the output to the Standard output,

out = new OutputStreamWriter(System.out, "UTF8");

What do I need to change in order for this to pass teh variable simply back to the code.

THanks for all your help in advancce.
WonderflubAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Why not use a Properties file to hold your search value?

Properties props = new Properties();
props.load(new FileInputStream("your-search.properties"));
String searchElement = props.getProperty("searchElement1");

....

if (eName.equals(searchElement)) {
    // do it
}
0
WonderflubAuthor Commented:
The information, or variable value, needs to be passed in from an external class file as they want me to create a reusable class that can be used in different applications, not jsut for this one.  so I need to parse the information I need from one class file, and send it to the other class file where indicated.

I know this is all very complicated for a newbie, but this is what they asked me to figure out, so I am trying to figure it out.  Before two weeks ago I only knew VB.
0
objectsCommented:
pass the class to your ctor and store a reference to it

public MyClass
{
   private MyOtherClass xxx;

   public MyClass(MyOtherClass xxx)
   {
      this.xxx = xxx;
   }

   ...


Then when you need to call the other class

String value = xxx.getValue();
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

WonderflubAuthor Commented:
I was out of town due to the death of my father and just returned monday.  I have only begun to try the variations of solutions offered and would appreciate this question being left open for jsut a bit longer.  THank you.
0
WonderflubAuthor Commented:
I have been trying to get objects solution to work but perhaps I am not familiar enough with Java to make it work.  It is not calling the external class properly.  It just ain't workin.
0
CEHJCommented:
>>I would like to use a new seperate class to do this in the interest of reusable code.

It's reusability doesn't depend on the number of entities you use, but on the way you design the code. You don't actually need to use another class to make it reusable. For maxiumum reusability:

1. Make the class read a text file, then changing search critieria is a matter of changing that text file, not recompiling code
2. If you use an ordinary text file, you can configure a List of elements to emit, giving you 0..n flexibility as opposed to 0..1
0
WonderflubAuthor Commented:
They want the dynamic information stored in an XML file, not a text file.  So the dynamic XML file needs to be parsed with a seperate class that is not coded into the original proggy.  Don't ask me to understand corporate thinking, I just do what I am told.  Hell, they are asking a VB programmer to build Rome in a day with java, does that even make sense.  But I never say die, I just try to use the resources available to me, like genius programmers around the world :-).
0
objectsCommented:
> It is not calling the external class properly.  It just ain't workin.

Spoecifically what are the problems?
0
CEHJCommented:
If they want you to use a separate xml file, you can just wrap a List in a custom class and then use this (example in docs):

http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLEncoder.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
:-)
0
WonderflubAuthor Commented:
Hey sorry that took so long, I took on about 4 projects before I could come back to this, plus life happened too, go figure but thanks you gave me jsut what I needed :-)
0
CEHJCommented:
No problem ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.