Hi Jorg All i had to do was to add the "base" as the parameter instead "returnValue" has one of the parameters for the convertAnother.
Thank you so much for you help =). Regards Ruben On Sun, Nov 18, 2012 at 10:37 PM, Ruben Fragoso <[email protected]>wrote: > Hello Jorg > > Thank you for coming back to me. > > So i test the following piece of code (following you suggestion): > > ============================= > while (reader.hasMoreChildren()) { > > MyBaseClass.Type type = > MyBaseClass.Type.valueOf(reader.getAttribute("type")); > MyBaseClass base = null; > reader.moveDown(); > > switch (type) { > case TypeOne: { > base = (ExtendedTypeOne) uc.convertAnother( > returnValue, ExtendedTypeOne.class); > } > case TypeTwo: { > } > default: { > } > } > reader.moveUp(); > if (null != base) { > returnValue.put(base.getName(), base); > } > } > > > > ========================== > > It gave me the same exception that i mentioned previously, about the > START_TAG and END_TAG > > Now one thing that i noticed is the following: if i inspect the reader > object when it enters the case, i notice that the element "parser" inside > the reader, has the entire XML objected side, with the right number of > attributes and with the all the attributes names correct. and that the > element "buf" inside the parser has the complete xml inside. > > There are several things which i don't understand: > > 1. why can't i get the XML string, as i don't see any method to retrieve > the XML of the current element in which the reader parsed and is currently > on (as in at the end of the element as you explained before). > > 2. I don't understand that if the reader already went through the xml > element and has everything parsed, why in the uc.convertAnother, we have to > reference its parent object. > > 3. should i use the version (convertAnother(Object o, Class type, > Converter cnvrtr); instead of the convertAnother(Object o, Class type) ? > > > Hope to hear from you and Thank you in advance :) > > Regards > Ruben > > > > > > > > > > > > > > > > > > > On Sat, Nov 17, 2012 at 6:08 PM, Jörg Schaible <[email protected]>wrote: > >> Ruben Fragoso wrote: >> >> > here is an example of the message that i get >> > >> > only START_TAG can have attributes END_TAG seen ... <MyCustomObject >> > widht="23" type="TypeOne" name="One" heigh="23"/>... @3:68 : only >> > START_TAG can have attributes END_TAG seen ... <MyCustomObject >> widht="23" >> > type="TypeOne" name="One" heigh="23"/>... @3:68 >> >> You test case does not produce this error. However, if the fragment of the >> first switch would have been executed, you get this. Let's simply assume, >> your code does not contain the condition for the empty XML value right >> after >> the move down: >> >> ================ %< ============== >> <MyCustomObject> >> <MyCustomObject widht="45" type="TypeThree" name="Three" >> diameter="78"|></MyCustomObject> >> <MyCustomObject widht="23" type="TypeOne" name="One" >> heigh="23"></MyCustomObject> >> ================ %< ============== >> >> Next would have been: >> >> ================ %< ============== >> reader.moveUp(); >> ================ %< ============== >> <MyCustomObject> >> <MyCustomObject widht="45" type="TypeThree" name="Three" >> diameter="78"></MyCustomObject>| >> <MyCustomObject widht="23" type="TypeOne" name="One" >> heigh="23"></MyCustomObject> >> ================ %< ============== >> >> You moved the pointer after the element's closing tag and now you suddenly >> try to process this tag by calling another converter, but actually the XML >> stream is now in an undefined state for this converter: >> >> ================ %< ============== >> ExtendedTypeOne extendedTypeOne = new >> ExtendedTypeOne(); >> extendedTypeOne = >> (ExtendedTypeOne)uc.convertAnother( >> extendedTypeOne, ExtendedTypeOne.class); >> ================ %< ============== >> >> What you actually want is: >> >> ================ %< ============== >> MyCustomObject returnValue = new MyCustomObject(); >> while (reader.hasMoreChildren()) { >> reader.moveDown(); >> // check now for the tag name, if you want to be sure it is >> "MyCustomObject" >> MyBaseClass.Type type = >> MyBaseClass.Type.valueOf(reader.getAttribute("type")); >> MyBaseClass base = null; >> switch (type) { >> case TypeOne: { >> base = (ExtendedTypeOne)uc.convertAnother( >> returnValue, ExtendedTypeOne.class); >> break; >> } >> case TypeTwo: { >> } >> default: { >> } >> } >> reader.moveUp(); >> returnValue.put(???, base); >> } >> return returnValue; >> ================ %< ============== >> >> And now compare this with your code in the marshall method. All calls to >> the >> reader have their exact equivalent with the ones to the writer. Also note >> the parameters for the call to call another converter. >> >> - Jörg >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >
