Unmarshaller unexpected element
843789May 8 2009 — edited May 11 2009Hi all, i have this problem, i have built this schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/SchemaWRequest"
xmlns:tns="http://xml.netbeans.org/schema/SchemaWRequest"
elementFormDefault="qualified">
<xsd:element name="wrequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="header">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="from">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
<xsd:element name="to">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="params">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="param" maxOccurs="1">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="value" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
from this schema with jaxb make java object and build this xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wrequest xmlns="http://xml.netbeans.org/schema/SchemaWRequest">
<header>
<from>saf_10_0</from>
<to></to>
</header>
<params>
<param name="saf_OI_LEFT_Wing_1"/>
<param name="LEFT_Wing"/>
<param name="1"/>
</params>
</wrequest>
i am sending this xml to another aplication and want to read the xml, so i used again jaxb but now Unmarshaling and some time he is working and some time he give me this error:
unexpected element (uri:"", local:"wrequest"). Expected elements are <{http://xml.netbeans.org/schema/SchemaWRequest}wrequest>
code where i am unmarshaling is this:
request is my xml in String
try{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
docNew = db.parse(new InputSource(new StringReader(request)));
} catch (Exception e) {
e.printStackTrace();
}
try {
javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(res.getClass().getPackage().getName());
javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
res = (Wrequest)unmarshaller.unmarshal(docNew);
} catch (javax.xml.bind.JAXBException ex) {
// XXXTODO Handle exception
java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N
}
same error is when i use unmarshaller.unmarshal(file) or unmarshaller.unmarshal(StreamReader)
i dont know what to do, i have clean all and start again, no problems with schema, no problem with marschaling, but when i want the same unmarshaling there is this error