• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsd:unique not working with xml beans

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi need to build a unique contraint using a xsd .
capabilities will have may capability , but capability should be unique


<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: xsd file Version: 0.3 Update: 09/09/2008 This program is
the confidential and proprietary product of mFormation Technologies
Inc. Any unauthorized use, reproduction or transfer of this program is
strictly prohibited. Copyright � 1999-2008 mFormation Technologies
Inc. (subject to limited distribution and restricted disclosure only.)
All rights reserved.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://services.mformation.com/MFServices/" xmlns:tns="http://services.mformation.com/MFServices/"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:simpleType name="Type">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Bag" />
<xsd:enumeration value="Sequence" />
<xsd:enumeration value="Literal" />
<xsd:enumeration value="Boolean" />
<xsd:enumeration value="Number" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Values">
<xsd:sequence>
<xsd:element type="xsd:string" name="Value" minOccurs="0"
maxOccurs="unbounded" nillable="false" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ValidValues">
<xsd:sequence>
<xsd:element type="xsd:string" name="Value" minOccurs="0"
maxOccurs="unbounded" nillable="false" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Capability">
<xsd:sequence>
<xsd:element type="xsd:string" name="Comment" minOccurs="1"
maxOccurs="1" nillable="false" />
<xsd:element type="xsd:string" name="Name" minOccurs="1"
maxOccurs="1" nillable="false" />
<xsd:element type="tns:Type" name="Type" minOccurs="1"
maxOccurs="1" nillable="false" />
<xsd:element type="tns:Values" name="Values" minOccurs="1"
maxOccurs="1" nillable="false" />
<xsd:element type="tns:ValidValues" name="ValidValues"
minOccurs="1" maxOccurs="1" nillable="false" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Capabilities" nillable="false">
<xsd:complexType>
<xsd:sequence>
<xsd:element type="xsd:string" name="SchemaName"
minOccurs="1" maxOccurs="1" nillable="false" />
<xsd:element type="tns:Capability" name="Capability"
minOccurs="1" maxOccurs="unbounded" nillable="false">

<xsd:unique name="un_name">
<xsd:selector xpath="Capability" />
<xsd:field xpath="Name" />
</xsd:unique>


</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

xml bean validation does not work

for the follwing case

<?xml version="1.0" encoding="utf-8"?>
<tns:Capabilities xmlns:tns="http://services.mformation.com/MFServices/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://services.mformation.com/MFServices/Device_Capabilities_v0.3.xsd">
<tns:SchemaName>TelstraSchemav1.0</tns:SchemaName>
<tns:Capability>
<tns:Comment>Description: Indicates what carkit the device supports. Examples: "Direct connection", "Inductive coupling", "None"</tns:Comment>
<tns:Name>t.Carkit</tns:Name>
<tns:Type>Literal</tns:Type>
<tns:Values>
<tns:Value>Direct connection</tns:Value>
</tns:Values>
<tns:ValidValues>
<tns:Value>Direct connection</tns:Value>
<tns:Value>Inductive coupling</tns:Value>
<tns:Value>None</tns:Value>
</tns:ValidValues>
</tns:Capability>
<tns:Capability>
<tns:Comment>Description: Indicates what carkit the device supports. Examples: "Direct connection", "Inductive coupling", "None"</tns:Comment>
<tns:Name>t.Carkit</tns:Name>
<tns:Type>Literal</tns:Type>
<tns:Values>
<tns:Value>Direct connection</tns:Value>
</tns:Values>
<tns:ValidValues>
<tns:Value>Direct connection</tns:Value>
<tns:Value>Inductive coupling</tns:Value>
<tns:Value>None</tns:Value>
</tns:ValidValues>
</tns:Capability>
</tns:Capabilities>

xml bean validation


C:\Requirements\phase 2\new xsd>validate Device_Capabilities_v0.3.xsd Device_Capabilities_v0.3-duplicate.xml
Device_Capabilities_v0.3-duplicate.xml valid.
C:\Requirements\phase 2\new xsd>
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just modify the xsd to define the unique constraint as follows:



Your unique constraint definition did not have proper namespaces.
Also, the unique constraint must be placed in the element from where you specify your selector xpath.
You had placed it inside Capability, and the selector specified the xpath as Capability.
It will never find Capability element inside Capability, so even if the namespace was correct, it would not yield the desired results.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic