title: javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
body: <p>I am getting this error, while unmarshalling a string. I have created Java files using JAXB.</p>
  
  <pre><code>JAXBContext jaxbContext = JAXBContext.newInstance(DocumentType.class);
  Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
  // Input string posted below
  DocumentType dType = (DocumentType) unmarshaller.unmarshal(new StringReader("input string"));
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd", local:"document"). Expected elements are (none)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:243)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:238)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1048)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:483)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:465)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:602)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3065)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:881)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)
      at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175)
      at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
      at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:214)
      at JaxbTest.main(JaxbTest.java:19)
  </code></pre>
  
  <p>XSD:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema targetNamespace="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd"
      elementFormDefault="qualified"&gt;
  
      &lt;xs:element name="document" type="tns:documentType"&gt;&lt;/xs:element&gt;
  
      &lt;xs:complexType name="documentType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="businessCard" type="tns:businessCardType" minOccurs="0" maxOccurs="1"&gt;&lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="businessCardType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="field" type="tns:fieldType" minOccurs="0" maxOccurs="unbounded"&gt;&lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="fieldType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"&gt;
              &lt;/xs:element&gt;
              &lt;xs:element name="characters" type="tns:charactersType" minOccurs="0" maxOccurs="1"&gt;&lt;/xs:element&gt;
              &lt;xs:element name="fieldComponents" type="tns:fieldComponentsType" minOccurs="0" maxOccurs="1"&gt;&lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="type" type="tns:typeType"&gt;&lt;/xs:attribute&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:simpleType name="typeType"&gt;
          &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="Name"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Phone"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Mobile"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Fax"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Company"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Job"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Address"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Email"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Web"&gt;&lt;/xs:enumeration&gt;
              &lt;xs:enumeration value="Text"&gt;&lt;/xs:enumeration&gt;
          &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  
      &lt;xs:complexType name="charactersType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="char" type="tns:charType" minOccurs="0" maxOccurs="unbounded"&gt;&lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="charType"&gt;
          &lt;xs:simpleContent&gt;
              &lt;xs:extension base="xs:string"&gt;
                  &lt;xs:attribute name="suspicious" type="xs:boolean" use="optional"&gt;&lt;/xs:attribute&gt;
              &lt;/xs:extension&gt;
          &lt;/xs:simpleContent&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="fieldComponentsType"&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="fieldComponent" type="tns:fieldComponentType" minOccurs="0" maxOccurs="unbounded"&gt;&lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
  
      &lt;xs:complexType name="fieldComponentType"&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1"&gt;
          &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
        &lt;xs:attribute name="type" type="tns:fieldComponentTypeType"&gt;&lt;/xs:attribute&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:simpleType name="fieldComponentTypeType"&gt;
        &lt;xs:restriction base="xs:string"&gt;
          &lt;xs:enumeration value="FirstName"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="MiddleName"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="LastName"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="ExtraName"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="PhonePrefix"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="PhoneCountryCode"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="PhoneCode"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="PhoneBody"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="PhoneExtension"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="ZipCode"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="Country"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="City"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="StreetAddress"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="JobPosition"&gt;&lt;/xs:enumeration&gt;
          &lt;xs:enumeration value="JobDepartment"&gt;&lt;/xs:enumeration&gt;
        &lt;/xs:restriction&gt;
      &lt;/xs:simpleType&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Input string:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd" xmlns="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd"&gt;
  &lt;businessCard&gt;
  &lt;field type="Phone"&gt;
    &lt;value&gt;783-37-00&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Phone"&gt;
    &lt;value&gt;783-37-01&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Fax"&gt;
    &lt;value&gt;783-26-63&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Email"&gt;
    &lt;value&gt;john_sm@abbyy.com&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Web"&gt;
    &lt;value&gt;www.abbyy.com&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Address"&gt;
    &lt;value&gt;Otradnaya str., 2b, bld.6, 127273, Moscow, Russia&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Name"&gt;
    &lt;value&gt;John Smith&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Company"&gt;
    &lt;value&gt;ABBYY Headquarters&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Job"&gt;
    &lt;value&gt;Product Analyst&lt;/value&gt;
  &lt;/field&gt;
  &lt;field type="Text"&gt;
    &lt;value&gt;ABBYY ABBYY Headquarters John Smith Product Analyst ABBYY Headquarters Otradnaya str., 2b, bld.6, 127273, Moscow, Russia Tel: 783-37-00 Fax: 783-26-63 john_sm@abbyy.com www.abbyy.com &lt;/value&gt;
  &lt;/field&gt;
  &lt;/businessCard&gt;
  &lt;/document&gt;
  </code></pre>