users@jaxb.java.net

DefaultValidationEventHandler

From: lissette <glorianchu18_at_hotmail.com>
Date: Thu, 7 Jun 2007 11:15:09 -0700 (PDT)

I work witg JAXB and I have this error:
DefaultValidationEventHandler: [ERROR]: tag name "description" is not
allowed. Possible tag names are: <product>
     Location:
Error1: javax.xml.bind.UnmarshalException: tag name "description" is not
allowed. Possible tag names are: <product>
 - with linked exception:
[com.sun.msv.verifier.ValidityViolation: tag name "description" is not
allowed. Possible tag names are: <product>]

My class is:

public void catalogos(String nomProd, String descripcion,
                          String nomEmp, int Stock, double precio){
                try {
                        //ponemos la ruta donde esta jaxb.properties
                        JAXBContext jc = JAXBContext.newInstance("generated");
                        Unmarshaller u = jc.createUnmarshaller();
                        u.setValidating(true);
                        
                        InputStream in = new FileInputStream("catalogs.xml");
                        if(in == null) {
                                //lo mismo tngo q crearlo
                                System.out.println("No encuentro el fichero");
                                return;
                        }//if
                        System.out.println("aki");
                        //construimos el modelo a partir el stream de entrada
                        Catalogs mifichero = (Catalogs)u.unmarshal(in);
                        System.out.println("aki llego");
                        //recuperamos la lista de catalogos y productos
                        List catalogo = mifichero.getCatalog();
                        // añadimos un nuevo catalogo
            CatalogTypeImpl nuevoCatalogo = new CatalogTypeImpl();
            System.out.println("aki tb llego");
            // establecemos los elementos
            nuevoCatalogo.setName("Cafes");
            nuevoCatalogo.setCatalogID("2");
            nuevoCatalogo.setDescription("El catalogo contiene Cafes");
            //Aqui añadimos productos para el catalogo
            ProductTypeImpl nuevoProducto = new ProductTypeImpl();
            //el codigo del producto aleatorio o paso el id del reg???
            nuevoProducto.setProductID("C349K7");
            nuevoProducto.setProductName(nomProd);
            nuevoProducto.setPrice(new BigDecimal(precio));
            nuevoProducto.setVendor(nomEmp);
            //nuevoProducto.setProperty(descripcion); no se como va???
            // añadimos al catalogo nuevos productos
             
            List prod = new ArrayList();
           
           // catalogo.add(nuevoProducto); Si lo añado al primer catalogo
            //lo añado al segundo catalogo
            catalogo.add(nuevoCatalogo);
            catalogo.add(nuevoProducto);
            
            // vamos a pintar ahora el arbol XML generado para asegurarnos
que se ha añadido
           Marshaller formateador = jc.createMarshaller();
           formateador.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
           formateador.marshal( mifichero, System.out );
            
            // ahora escribimos a un fichero, en el correcto juego de
caracteres
           formateador.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
           FileOutputStream salida = new FileOutputStream("salida.xml");
           formateador.marshal( mifichero, salida);

                }catch(JAXBException e){
                        System.out.println("Error1: "+e.toString());
                }//catch
                catch(Exception el){
                        System.out.println("Error2: "+el.toString());
                }//catch
        }//catalogos
my Schema is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
         
        <xsd:element name="product">
                <xsd:complexType>
                        <xsd:sequence>
                                <!-- Definicion de los elementos nombre y precio -->
                                <xsd:element name="productName" type="xsd:string" />
                                <xsd:element name="vendor" type="xsd:string" />
                                <xsd:element ref="property" minOccurs="0" maxOccurs="1"/>
                                <xsd:element name="price" type="xsd:decimal" />
                        </xsd:sequence>
                        <xsd:attribute name="productID" type="xsd:string" use="required" />
                </xsd:complexType>
        </xsd:element>
        
        <xsd:element name="property">
                <xsd:complexType>
                        <xsd:attribute name="name" type="xsd:string" use="optional"/>
                </xsd:complexType>
        </xsd:element>

        <xsd:element name="catalog">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element name="description" type="xsd:string" maxOccurs="1"/>
                                <xsd:element ref="product" minOccurs="1" maxOccurs="unbounded"/>
                        </xsd:sequence>
                        <xsd:attribute name="catalogID" type="xsd:string" use="required" />
                        <xsd:attribute name="name" type="xsd:string" />
                </xsd:complexType>
        </xsd:element>

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

and my XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalogs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="catalogs.xsd">
    <catalog catalogID="1" name="Cafes">
        <description>El catalogo contiene Cafes</description>
        <product productID="C349K4">
                <productName>Arabica</productName>
                <vendor>Cafetaras Norte S.A</vendor>
                <property name="Remark"></property>
                    <price>13.5</price>
        </product>
        <product productID="C349K5">
                    <productName>Mocha Java</productName>
                <vendor>Cafetaras Norte S.A</vendor>
                <property name="Remark"></property>
                          <price>11.95</price>
        </product>
        <product productID="C349K6">
                    <productName>Sumatra</productName>
                <vendor>Hig S.A</vendor>
                <price>12.5</price>
        </product>
    </catalog>
</catalogs>

Caould you help me??
thanks very much
-- 
View this message in context: http://www.nabble.com/DefaultValidationEventHandler-tf3885479.html#a11013436
Sent from the java.net - jaxb users mailing list archive at Nabble.com.