Dreaded
I have reviewed the previous threads on this but the final resolution involved something I am already doing correctly. Here is stack trace:
org.xml.sax.SAXParseException: unexpected root element (uri:"", local:"CancelPenalty"). Expected elements are
at generated.impl.runtime.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:113)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at generated.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178)
at populateDB.Populate.getCancelPenalty(Populate.java:26)
at populateDB.Populate.main(Populate.java:13)
linked to
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: unexpected root element (uri:"", local:"CancelPenalty"). Expected elements are ]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:298)
at generated.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:144)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:178)
at populateDB.Populate.getCancelPenalty(Populate.java:26)
at populateDB.Populate.main(Populate.java:13)
Here are my xsd and xml files:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="CancelPenalty">
<xs:sequence>
<xs:element name="SKUGroupCancelPolicySetID" type="xs:int"/>
<xs:element name="CancelPenaltyDefaultBool" type="xs:boolean"/>
<xs:element name="CancelPenaltyHourCnt" type="xs:int"/>
<xs:element name="CancelPenaltyLogID" type="xs:int"/>
<xs:element name="CancelPenaltyCostAmt" type="xs:float"/>
<xs:element name="CancelPenaltyCostRate" type="xs:float"/>
<xs:element name="CancelPenaltyCostDayCnt" type="xs:int"/>
<xs:element name="CancelPenaltyPriceAmt" type="xs:float"/>
<xs:element name="CancelPenaltyPriceRate" type="xs:float"/>
<xs:element name="CancelPenaltyPriceDayCnt" type="xs:int"/>
<xs:element name="UpdateTPID" type="xs:int"/>
<xs:element name="UpdateTUID" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="UTF-8" ?>
<CancelPenalty>
<SKUGroupCancelPolicySetID>27950</SKUGroupCancelPolicySetID>
<CancelPenaltyDefaultBool>1</CancelPenaltyDefaultBool>
<CancelPenaltyHourCnt>0</CancelPenaltyHourCnt>
<CancelPenaltyLogID>1211679</CancelPenaltyLogID>
<CancelPenaltyCostAmt>0</CancelPenaltyCostAmt>
<CancelPenaltyCostRate>.0000</CancelPenaltyCostRate>
<CancelPenaltyCostDayCnt>0</CancelPenaltyCostDayCnt>
<CancelPenaltyPriceAmt>0</CancelPenaltyPriceAmt>
<CancelPenaltyPriceRate>1.0000</CancelPenaltyPriceRate>
<CancelPenaltyPriceDayCnt>0</CancelPenaltyPriceDayCnt>
<UpdateTPID>20001</UpdateTPID>
<UpdateTUID>49627832</UpdateTUID>
</CancelPenalty>
And here is my code:
public static void getCancelPenalty() {
String jaxbContext = "generated";
String cancelPenaltyFilename = "CancelPenaltyOne.xml";
JAXBContext jc = null;
Unmarshaller u = null;
CancelPenaltyImpl cancelPenalty = null;
try {
jc = JAXBContext.newInstance(jaxbContext);
u = jc.createUnmarshaller();
cancelPenalty = (CancelPenaltyImpl) u.unmarshal(
new FileInputStream(cancelPenaltyFilename));
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
int updateTUID = cancelPenalty.getUpdateTUID();
System.out.println("These values were retrieved from " +
"the Cancel Penalty object:");
System.out.println("UpdateTUID: "+ updateTUID);
}
}
Any ideas why the xml file is not parsing correctly?
Matthew

