1

I have the following XML content:

<?xml version="1.0" encoding="UTF-8"?>
<success>
  <accessedResource>/bioportal/provisional</accessedResource>
  <accessDate>2013-04-23 20:50:58.139 PDT</accessDate>
  <data>
    <classBean>
      <id>http://purl.bioontology.org/ontology/provisional/9cc8b147-e193-4d23-a3a1-9da34eeeb5a9</id>
      <fullId>http://purl.bioontology.org/ontology/provisional/9cc8b147-e193-4d23-a3a1-9da34eeeb5a9</fullId>
      <label>OzbbBugGbIINcdpSY</label>
      <synonyms>
        <string>ux0fBN http://www.ggiodpc.com/www.6shpFpANPwYnffbs9P5rsRN67oJWDZuQ.com.php</string>
      </synonyms>
      <definitions>
        <string>ux0fBN http://www.ggiodpc.com/www.6shpFpANPwYnffbs9P5rsRN67oJWDZuQ.com.php</string>
      </definitions>
      <relations>
        <entry>
          <string>provisionalRelatedNoteId</string>
          <string>Note_3df7809d-aac8-4cf8-b320-f3eecceacd4e</string>
        </entry>
        <entry>
          <string>provisionalTermStatus</string>
          <null/>
        </entry>
        <entry>
          <string>provisionalCreated</string>
          <date>2013-04-09 20:06:23.79 PDT</date>
        </entry>
        <entry>
          <string>provisionalPermanentId</string>
          <null/>
        </entry>
        <entry>
          <string>provisionalRelatedOntologyIds</string>
          <list>
            <int>1057</int>
          </list>
        </entry>
        <entry>
          <string>provisionalSubmittedBy</string>
          <int>38382</int>
        </entry>
        <entry>
          <string>provisionalUpdated</string>
          <null/>
        </entry>
        <entry>
          <string>provisionalSubclassOf</string>
          <org.openrdf.model.URI>
            <uriString>http://purl.bioontology.org/ontology/RID/RID0</uriString>
            <localNameIdx>-1</localNameIdx>
          </org.openrdf.model.URI>
        </entry>
      </relations>
    </classBean>
  </data>
</success>

I want to validate it using the following XML Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
           targetNamespace="http://bioontology.org/bioportal/classBeanSchema#"
           xmlns:c="http://bioontology.org/bioportal/classBeanSchema#">
    <xs:element name="success">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="c:accessedResource"/>
                <xs:element ref="c:accessDate"/>
                <xs:element ref="c:data"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="accessedResource" type="xs:string"/>
    <xs:element name="accessDate" type="xs:string"/>

    <xs:element name="data">
        <xs:complexType>
            <xs:all>
                <xs:element ref="c:list" minOccurs="0" maxOccurs="1"/>
                <xs:element ref="c:classBean" minOccurs="0" maxOccurs="1"/>
            </xs:all>
        </xs:complexType>
    </xs:element>
    <xs:element name="classBean">
        <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="c:fullId" maxOccurs="1" minOccurs="0"/>
                <xs:element ref="c:id" maxOccurs="1" minOccurs="0"/>
                <xs:element ref="c:label" maxOccurs="1" minOccurs="0"/>
                <xs:element ref="c:relations" maxOccurs="1" minOccurs="0"/>
                <xs:element name="type" type="xs:string" maxOccurs="1" minOccurs="0"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>

    <xs:element name="fullId" type="xs:string"/>
    <xs:element name="id" type="xs:string"/>
    <xs:element name="label" type="xs:string"/>

    <xs:element name="relations">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" maxOccurs="unbounded" ref="c:entry"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="entry">
        <xs:complexType>
            <xs:sequence>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="string" type="xs:string"/>
                    <xs:element ref="c:list"/>
                </xs:choice>
                <xs:element minOccurs="0" ref="c:int"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="list">
        <xs:complexType>
            <xs:sequence>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element minOccurs="0" maxOccurs="unbounded" ref="c:classBean"/>
                    <xs:element minOccurs="0" maxOccurs="unbounded" name="string" type="xs:string"/>
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="int" type="xs:integer"/>

</xs:schema>

For the validation I use the following code snippet:

SchemaFactory schemaFactory =  SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);

The following Exception is thrown, which indicates to me that the XML file is not valid given the Schema:

org.xml.sax.SAXParseException; systemId: file:/C:/xml.xml; lineNumber: 2; columnNumber: 10; cvc-elt.1: Cannot find the declaration of element 'success'.

I do not understand the message, since in line 2 i can find the 'success' element. Can somebody help?

Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
hansi
  • 2,278
  • 6
  • 34
  • 42

1 Answers1

0

Your XML is wrong as per your Schema, have a look:

XML:

<classBean>
  <id>http://purl.bioontology.org/ontology/provisional/9cc8b147-e193-4d23-a3a1-9da34eeeb5a9</id>
  <fullId>http://purl.bioontology.org/ontology/provisional/9cc8b147-e193-4d23-a3a1-9da34eeeb5a9</fullId>
  <label>OzbbBugGbIINcdpSY</label>
  <synonyms>
    <string>ux0fBN http://www.ggiodpc.com/www.6shpFpANPwYnffbs9P5rsRN67oJWDZuQ.com.php</string>
  </synonyms>
  <definitions>
    <string>ux0fBN http://www.ggiodpc.com/www.6shpFpANPwYnffbs9P5rsRN67oJWDZuQ.com.php</string>
  </definitions>

XSD

  <xs:element name="classBean">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="c:fullId" maxOccurs="1" minOccurs="0"/>
        <xs:element ref="c:id" maxOccurs="1" minOccurs="0"/>
        <xs:element ref="c:label" maxOccurs="1" minOccurs="0"/>
        <xs:element ref="c:relations" maxOccurs="1" minOccurs="0"/>
        <xs:element name="type" type="xs:string" maxOccurs="1" minOccurs="0"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>

NOTE: 'synonyms' and 'definitions' is not valid child of 'classBean' element.

Same thing for 'entry' element where you have 'date' and 'null' as child but as per schema it is not valide. There are some more errors.

There might be a possiblity that SAX Parser is not reflecting correct line number of errors.

Navin Rawat
  • 3,208
  • 1
  • 19
  • 31