Menu

#2 Reading Arguments from XML

open
nobody
None
5
2003-10-08
2003-10-08
Anonymous
No

Hi,

I am evaluating the JOX software that is very easy to
convert Java Beans object to XML and back. It is truly
amazing. I am actually stuck in one important scenario:

My XML file looks like:
<item-list>
<stock_info name="YYY">SYM</stock_info>
</item-list>

I want to write an particular java bean code to get
access to symbol SYM.
can you please tell me how to do it?

thanks. I appreciate your help.
Manish

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Can someone reply to this issue? I am having the same
    problem.

     
  • Ulrich Rueth

    Ulrich Rueth - 2004-04-07

    Logged In: YES
    user_id=347243

    Yes, I am desparately looking for this as well!! Can you
    already forsee any solution?

     
  • PapaBear

    PapaBear - 2004-07-29

    Logged In: YES
    user_id=1093420

    Hi all,
    I have a created a patch for this. You only have to modify
    the JOXSAXBeanInput class. The patch is:
    /home/alva/src/Jox-1.17b3/com/wutka/jox >diff -bw
    JOXSAXBeanInput.java Orig_JOXSAXBeanInput.java
    6,8d5
    < // Begin Change --- Alva Powell 7/28/04
    < import org.xml.sax.helpers.AttributesImpl;
    < // End Change --- Alva Powell 7/28/04
    543,549c540
    < ((ob instanceof DictElement) && !isMapType
    (((DictElement)ob).valueClass))
    < // Begin Change --- Alva Powell 7/28/04
    < || ((ob instanceof ObjectInfo)
    < && ! ((ObjectInfo) ob).getValueLoaded()
    < && (length > 0))
    < )
    < // End Change --- Alva Powell 7/28/04
    ---
    > ((ob instanceof DictElement) && !isMapType
    (((DictElement)ob).valueClass)))
    555,558d545
    < // Begin Change --- Alva Powell 7/28/04
    < if (ob instanceof ObjectInfo)
    < {
    < ((ObjectInfo) ob).setValueLoaded(true);
    560,561d546
    < // End Change --- Alva Powell 7/28/04
    < }
    662,676d646
    < // Begin Change --- Alva Powell 7/28/04
    < // What an ugly hack...
    < else if(stackOb instanceof ObjectInfo)
    < {
    < if (null != valueStr)
    < {
    < Attributes myAtts;
    < myAtts = new AttributesImpl();
    <
    < ((AttributesImpl)myAtts).addAttribute
    ("","Val","Val","CDATA",valueStr);
    <
    < processAttributes((ObjectInfo) stackOb,
    myAtts);
    < }
    < }
    < // End Change --- Alva Powell 7/28/04
    1115,1117d1084
    < // Begin Change --- Alva Powell 7/28/04
    < private boolean valueLoaded;
    < // End Change --- Alva Powell 7/28/04
    1128,1139d1094
    <
    < // Begin Change --- Alva Powell 7/28/04
    < public void setValueLoaded(boolean flag)
    < {
    < valueLoaded = flag;
    < }
    <
    < public boolean getValueLoaded()
    < {
    < return valueLoaded;
    < }
    < // End Change --- Alva Powell 7/28/04

    You will have to add a method public void setVal(String
    value) to your class in order for this patch to work. Sorry I
    know it is a little UGLY... Just didn't have time to come up
    with a better solution.

     
  • PapaBear

    PapaBear - 2004-07-29

    Logged In: YES
    user_id=1093420

    If any one would like assistance with the patch I put up feel
    free to email me alvapowell <AT> netscape <DOT> net.

     
  • PapaBear

    PapaBear - 2004-07-29

    Logged In: YES
    user_id=1093420

    One more follow up on this. After a nights sleep I realized I
    could make a slight mod and this would actually work much
    better.

    Change the following line (which is new line 671)
    ((AttributesImpl)myAtts).addAttribute
    ("","Val","Val","CDATA",valueStr);

    to:

    ((AttributesImpl)myAtts).addAttribute
    ("",unqualifiedName,unqualifiedName,"CDATA",valueStr);

    This will cause JOX to use setStock_info in the above
    example. Also the parameter type in the setStock_info(String
    value) can be any simple type. I am not sure if you can get
    away with a complex (object) here. I don't think so, but I
    don't need to in my application so I am NOT going to play
    with it to try and figure it out.

     

Log in to post a comment.