A. M. Mérida
A. M. Mérida

Reputation: 2618

Create different element in XSD

I have a XSD modified to add new item without having to create a new XSD. Currently I have a single element in this case is "tire".

I created an element of type "tire".

<xs:element name="tire" type="x:tire" />

but I get an error when validating. Error:

Not valid.
Error - Line 4, 43: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 43; src-resolve.4.2: Error resolving component 'x:tire'. It was detected that 'x:tire' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'null'. If this is the incorrect namespace, perhaps the prefix of 'x:tire' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'null'.
Error - Line 4, 43: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 43; src-resolve: Cannot resolve the name 'x:tire' to a(n) 'type definition' component.

XML

<?xml version="1.0" encoding="UTF-8"?>
<tire trademark="runway" id="369954" product-type="tire">
  <url>http://www.tire.es/product/369954.html</url>
  <price>28.95</price>
  <specs>
    <spec name="b_homologation">0</spec>
    <spec name="b_xl">0</spec>
    <spec name="b_runflat">0</spec>
    <spec name="s_drawing_type">simétrico</spec>
    <spec name="s_consumption">f</spec>
    <spec name="i_noise">69</spec>
    <spec name="s_grip">c</spec>
  </specs>
</tire>

XSD

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:x="http://www.w3.org/2001/XMLSchema">

  <xs:element name="tire" type="x:tire" />

  <xs:complexType name="product">
    <xs:sequence>
      <xs:element type="xs:anyURI" name="url" />
      <xs:element type="xs:double" name="price" />

      <xs:element name="specs" maxOccurs="unbounded"
        minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="spec" maxOccurs="unbounded"
              minOccurs="0">
              <xs:complexType>
                <xs:simpleContent>
                  <xs:extension base="xs:string">
                    <xs:attribute type="xs:string" name="name"
                      use="optional" />
                  </xs:extension>
                </xs:simpleContent>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="features" maxOccurs="unbounded"
        minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="feature" maxOccurs="unbounded"
              minOccurs="0">
              <xs:complexType>
                <xs:simpleContent>
                  <xs:extension base="xs:string">
                    <xs:attribute type="xs:string" name="name"
                      use="optional" />
                  </xs:extension>
                </xs:simpleContent>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute type="xs:string" name="id" />
    <xs:attribute type="xs:string" name="product-type" />
  </xs:complexType>

  <xs:complexType name="tire">
    <xs:complexContent>
      <xs:extension base="product">
        <xs:attribute type="xs:string" name="model" />
        <xs:attribute type="xs:string" name="trademark" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

<xs:element name="products">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="tire" maxOccurs="unbounded"
        minOccurs="0" type="x:tire" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

</xs:schema>

The new products will add them as elements.

<xs:element name="glass" maxOccurs="unbounded" minOccurs="0" type="x:glass" />

thanks.

Upvotes: 0

Views: 1972

Answers (1)

Michael Kay
Michael Kay

Reputation: 163675

The type "tire" is not in the XSD namespace http://www.w3.org/2001/XMLSchema, it is in the target namespace of the schema document, which in this case is "no namespace". So it should be type="tire" rather than type="x:tire".

Upvotes: 2

Related Questions