Question

I keep getting this error and I can't figure out what is wrong in my code (I am using NetBeans IDE 6.7.1:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'manufacturer'.  One of '{manufacturer}' is expected. [14] 
cvc-complex-type.2.4.a: Invalid content was found starting with element 'manufacturer'. One of '{manufacturer}' is expected. [23] 
cvc-complex-type.2.4.a: Invalid content was found starting with element 'manufacturer'. One of '{manufacturer}' is expected. [32] 
XML validation finished.

Here is my XML code:

<?xml version="1.0" encoding="UTF-8"?>
<jobList xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com jobList.xsd">

<job status="unallocated">
    <resource employeeId="AD145267" type="Laptop">
        <manufacturer>Dell</manufacturer>
        <model>Vostro 1540</model>
        <serialNumber>764839211-19-H</serialNumber>
    </resource>
    <problem reported="2012-01-22T15:23:00">Fails to boot</problem>
</job>

<job status="unallocated">
    <resource employeeId="TE135218" type="Wireless printer">
        <manufacturer>Epson</manufacturer>
        <model>Stylus SX435W</model>
        <serialNumber>E4356-982312</serialNumber>
    </resource>
    <problem reported="2012-01-23T10:07:00">No wireless access</problem>
</job>

<job status="allocated">
    <resource type="Network drive">
        <manufacturer>G-Tech</manufacturer>
        <model>G-RAID Hard drive array</model>
        <serialNumber>783451287G</serialNumber>
    </resource>
    <problem reported="2012-01-24T11:02:00">Read errors reported during rebuild</problem>

    <work jobId="564">
        <technician allocated="2012-01-24T15:05:00">T541</technician>
        <note>Spoke to Eric about what happened.</note>
        <note>Ran phase 1 diagnostics - no errors reported</note>
    </work>
</job>

</jobList>

And here is the Schema Code

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3schools.com"   targetNamespace="http://www.w3schools.com">

<xs:element name="jobList">
<xs:complexType>
  <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:element ref="job"/>
  </xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="job">
<xs:complexType>
  <xs:sequence>
    <xs:element ref="resource"/>
    <xs:element ref="problem"/>
    <xs:sequence minOccurs="0">
      <xs:element ref="work"/>
    </xs:sequence>
  </xs:sequence>
  <xs:attribute name="status" use="required">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="unallocated"/>
        <xs:enumeration value="allocated"/>
        <xs:enumeration value="completed"/>
        <xs:enumeration value="confirmed"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
</xs:complexType>
</xs:element>

<xs:element name="resource">
<xs:complexType>
  <xs:sequence>
    <xs:element name="manufacturer" type="xs:string"/>
    <xs:element name="model" type="xs:string"/>
    <xs:element name="serialNumber" type="xs:string"/>
  </xs:sequence>
  <xs:attribute name="employeeId" type="xs:string"/>
  <xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="problem">
<xs:complexType>
  <xs:simpleContent>
    <xs:extension base="xs:string">
      <xs:attribute name="reported" type="xs:dateTime" use="required"/>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>
</xs:element>

<xs:element name="work">
<xs:complexType>
  <xs:sequence>
    <xs:element ref="technician"/>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="note"/>
    </xs:sequence>
  </xs:sequence>
  <xs:attribute name="jobId" type="xs:positiveInteger" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="technician">
<xs:complexType>
  <xs:simpleContent>
    <xs:extension base="xs:string">
      <xs:attribute name="allocated" type="xs:dateTime" use="required"/>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="note" type="xs:string"/>
</xs:schema>

It looked at manufacturer and I'm struggling to see what is wrong. I will also link the relevant DTD code incase the extra info is useful.

<!ELEMENT resource (manufacturer, model, serialNumber)>
<!ELEMENT manufacturer (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEME.....
Was it helpful?

Solution

Your schema expects to find a <manufacturer> of no-namespace. Ex:

<manufacturer xmlns="">...</manufacturer>

But you actually want it to validate with {"http://www.w3schools.com":manufacturer} (from your target namespace). To declare that behaviour as default for all elements add elementFormDefault="qualified" to your XML Schema declaration:

<xs:schema ... elementFormDefault="qualified"> ... </xs:schema>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top