File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Using IDREFs with XML Schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Using IDREFs with XML Schema" Watch "Using IDREFs with XML Schema" New topic

Using IDREFs with XML Schema

Naveen Gabrani

Joined: Jul 12, 2000
Posts: 25
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?
I agree. Here's the link:
subject: Using IDREFs with XML Schema
jQuery in Action, 3rd edition