I don't think that this possible without specifying at least a partial
mapping. Don't forget that you do not have to specify a mapping for all
classes used, as Castor will use its (default) introspector for any
classes for which there's no mapping.
Werner
Rodney Ryan wrote:
> Hi Everyone,
>
> I am using Castor to unmarshal a very simple XML document and I wish to
> have Castor indicate when it encounters anything in the XML that it cannot
> unmarshal. I am not using a mapping file as the XML to Java conversion is
> simple and straight-forward.
>
> I have searched high and low and googled and looked in the javadocs and
> done all I can to find out how to do this, but to no success. Castor
> continues to silently ignore the error in the XML.
>
> So now I am asking you for help, and hoping someone will kindly answer this
> very simple question.
>
> Take the following class:
>
> public class Library {
>
> private List<String> books;
>
> public Library() {
> books = new LinkedList<String>();
> }
>
> public void addBook(String title) {
> books.add(title);
> }
>
> public String toString() {
> return "Books = " + books;
> }
> }
>
> with this XML file "library.xml" (the misspelled "boook" is intentional):
>
> <library>
> <book>War And Peace</book>
> <book>Ulysses</book>
> <boook>Crime And Punishment</boook>
> </library>
>
> and with this Castor application:
>
> public class CastorTest {
> public static void main(String[] args) {
> try {
> Unmarshaller unmarshaller = new Unmarshaller(Library.class);
> unmarshaller.setIgnoreExtraAttributes(false);
> unmarshaller.setIgnoreExtraElements(false);
> unmarshaller.setValidation(true);
> Reader reader = new FileReader(new File("library.xml"));
> Library library = (Library)unmarshaller.unmarshal(reader);
> System.out.println(library);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> The 3rd book in the library file is misspelled "boook". I want Castor to
> tell me somehow that this is something it does not understand.
>
> No matter what I do, the program runs without throwing an Exception or
> printing an error message. The output of the above is:
>
> Books = [War And Peace, Ulysses]
>
> Please answer this specific question:
>
> Exactly what should I add/remove/change in the
> CastorTest class above to accomplish this ?
>
> Thank you very much !
>
> - Rodney
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email