javaxmlxsdjaxbpmml

PMML 4.4 xml parse exception


Hi one of my project requirement is to create a PMML manually . Till 4.2 version it was working fine now im trying to do the same using 4.4 version but it is giving me the below error.

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"PMML"). Expected elements are <{https://www.dmg.org/PMML-4_4}AR>......

This is my sample code

String pmmlString="<?xml version=\"1.0\" encoding=\"UTF-8\"?><PMML xmlns=\"http://www.dmg.org/PMML-4_4\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"4.4\"></PMML>";
    PMML pmml = null;
    XMLStreamReader xsr = null;
    try {
        JAXBContext jc = JAXBContext.newInstance(PMML.class);
        Unmarshaller u = jc.createUnmarshaller();
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
        xif.setProperty(XMLInputFactory.IS_COALESCING, false);
        xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
        xsr = xif.createXMLStreamReader(new ByteArrayInputStream(pmmlString.getBytes()));

        pmml = (PMML) u.unmarshal(xsr);

    } catch(Exception e){
        e.printStackTrace();
    }finally {
        if (xsr != null) {
            try {
                xsr.close();
            } catch (Exception e) {

            }
        }
    }

Im following the exact same structure as mentioned in https://dmg.org/pmml/v4-4/GeneralStructure.html


Solution

  • when i convert the xsd to java jaxb creates the package-info.java which looks like below @javax.xml.bind.annotation.XmlSchema(namespace = "https://www.dmg.org/PMML-4_4", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.fico.carbon.pmml;

    once i remove the above annotation it started working