Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using IDREFs with XML Schema  RSS feed

Naveen Gabrani
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am using IDREFs in XML Schema to refer from one element to another, then there should be no need to give all the elements. So for example I have an element with a required property and id 1. Now I define another element of the same type. It just uses IDREF to refer to the first element. There should be no need to specify the required properties for the second element, as we are just refering to the other element using IDREFs. But I get verification errors saying that reqiured properties are not specified.
As an example, consider this XML Schema -
<xsd:schema targetNamespace="" xmlns:test="" xmlns:xsd="" elementFormDefault="qualified">
<xsd:element name="test" type="test:test"/>
<xsd:complexType name="test">
<xsd:element name="test.gears" nillable="true" maxOccurs="10">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="str" type="xsd:string"/>
<xsd:attribute name="ID" type="xsd:ID"/>
<xsd:attribute name="IDREF" type="xsd:IDREF"/>
The XML instance looks like this -
<?xml version="1.0" encoding="UTF-8"?>
<test:test xmlns:test="" xmlns:xsi="" xsi:schemaLocation=" c:\workbench\test.xsd">
<test:test.gears IDREF="a123">
<test:test.gears ID="a123">
This generates validation error (with XML-SPY) because for IDREF a123, str element is not specified. What is the point of using IDREF to refer to other element if I have to specify all the required properties again?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!