users@jaxb.java.net

javax.xml.bind.UnmarshalException

From: lissette <glorianchu18_at_hotmail.com>
Date: Thu, 17 May 2007 08:41:44 -0700 (PDT)

Hello!!
I work with Jaxb and have one error:

DefaultValidationEventHandler: [ERROR]: unexpected attribute "catalogID"
     Location:
Error: javax.xml.bind.UnmarshalException: unexpected attribute "catalogID"
 - with linked exception:
[com.sun.msv.verifier.ValidityViolation: unexpected attribute "catalogID"]

My class is:
import generated.*;
import generated.impl.*;

import javax.xml.bind.*;
import java.io.*;
import java.util.*;

public class Main {
        
        public static void main(String[] args) throws FileNotFoundException {
                try {
                        //ponemos la ruta donde esta jaxb.properties
                        JAXBContext jc = JAXBContext.newInstance( "generated" );
                        Unmarshaller u = jc.createUnmarshaller();
                        u.setValidating(true);
                        
                        InputStream in = new FileInputStream("catalogos.xml");
                        if(in == null) {
                                System.out.println("No encuentro el fichero");
                                return;
                        }//if
                        //construimos el modelo a partir el stream de entrada
                        Catalogos mifichero = (Catalogos)u.unmarshal(in );
                        //recuperamos la lista de catalogos
                        List catalogo = mifichero.getCatalogo();
                        int numero = catalogo.size();
                        System.out.println("El numero de catalogos es: " +numero );
                        for (int i = 0; i < numero; i++) {
                                Catalogo catalogoconcreto = (Catalogo)catalogo.get(i);
                                System.out.println(catalogoconcreto.getNombre());
                        }//for
                        
                }catch(JAXBException e){
                        System.out.println("Error: "+e.toString());
                }//catch
                catch(Exception el){
                        System.out.println("Error: "+el.toString());
                }//catch
        }//main
        
}//Main

And my schema is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
         
        <xsd:element name="producto">
                <xsd:complexType>
                        <xsd:sequence>
                                <!-- Definicion de los elementos nombre y precio -->
                                <xsd:element name="nombre" type="xsd:string" />
                                <xsd:element name="precio" type="xsd:decimal" />
                        </xsd:sequence>
                        <xsd:attribute name="productoID" type="xsd:ID" use="required" />
                </xsd:complexType>
        </xsd:element>

        <xsd:element name="catalogo">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element ref="producto" minOccurs="1" maxOccurs="unbounded"/>
                        </xsd:sequence>
                        <xsd:attribute name="catalogoID" type="xsd:ID" use="required" />
                        <xsd:attribute name="nombre" type="xsd:string" />
                </xsd:complexType>
        </xsd:element>

        <xsd:element name="catalogos">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element ref="catalogo" minOccurs="1" maxOccurs="unbounded"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
</xsd:schema>

And my XML is:

<?xml version="1.0" encoding="UTF-8"?>
<catalogos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="catalogos.xsd">
    <catalogo catalogID="1" nombre="Cafes">
        <producto productID="C349K4">
            <nombre>Arabica</nombre>
<!-- he quitado la descripcion del producto.... -->
                  <precio>13.5</precio>
        </producto>
        <producto productID="C349K5">
            <nombre>Mocha Java</nombre>
                  <precio>11.95</precio>
        </producto>
          <producto productID="C349K6">
            <nombre>Sumatra</nombre>
                  <precio>12.5</precio>
        </producto>
    </catalogo>
</catalogos>

Could you help me???thanks very much
-- 
View this message in context: http://www.nabble.com/javax.xml.bind.UnmarshalException-tf3772675.html#a10666663
Sent from the java.net - jaxb users mailing list archive at Nabble.com.