aspose file tools*
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
Author

Using IDREFs with XML Schema

Naveen Gabrani
Greenhorn

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="http://www.a.com/ns/community.txt/Portal_0020Repository/test" xmlns:test="http://www.a.com/ns/community.txt/Portal_0020Repository/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="test" type="test:test"/>
<xsd:complexType name="test">
<xsd:sequence>
<xsd:element name="test.gears" nillable="true" maxOccurs="10">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="str" type="xsd:string"/>
</xsd:choice>
<xsd:attribute name="ID" type="xsd:ID"/>
<xsd:attribute name="IDREF" type="xsd:IDREF"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
The XML instance looks like this -
<?xml version="1.0" encoding="UTF-8"?>
<test:test xmlns:test="http://www.a.com/ns/community.txt/Portal_0020Repository/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.a.com/ns/community.txt/Portal_0020Repository/test c:\workbench\test.xsd">
<test:test.gears IDREF="a123">
</test:test.gears>
<test:test.gears ID="a123">
<test:str>test</test:str>
</test:test.gears>
</test:test>
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?
Naveen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using IDREFs with XML Schema