XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 20th, 2004, 08:31 AM
ta0002 ta0002 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 ta0002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Define custom XSD rules

Hi, I have a problem in defining a custom rules in my XSD to validate XML file.
I use library Xerces-J-bin.2.6.2.zip, also My program is working fine without erros, but the problem is when I enforce the XSD to raise an error by modifying the XML.

So what I want is to tell me if my XSD is correct , and why the erros is not displayed.

XSD Sample: Schema validation
------------------------------------------------------------------------------------------------------------------------------------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron">
<xsd:complexType name="addressType">
<xs:annotation>
<xs:appinfo>
<schattern name="addressType_rules">
<xsd:rule name="country_UK">
<xsd:expression>
if(country = "UK") then
false()
else true()
</xsd:expression>
</xsd:rule>
<xsd:rule name="country_US">
<xsd:expression>
if(country = "US") then
false()
else
true()
</xsd:expression>
</xsd:rule>
</schattern>
</xs:appinfo>
</xs:annotation>
<xsd:sequence>
<xsd:choice minOccurs="0">
<xsd:element name="postcode" type="xsd:string" />
<xsd:element name="zipcode" type="xsd:string" />
</xsd:choice>
<xsd:element name="country" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="message">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="senderAddress" type="addressType" />
<xsd:element name="recipientAddress" type="addressType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
---------------------------------------------------------------------
XSD Sample: Schematron
---------------------------------------------------------------------

<xsd:schema xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="message">
<xsd:annotation>
<xsd:appinfo>
<schattern name="addressType_rules">
<sch:rule context="senderAddress">
<sch:assert diagnostics="atomRefFormat" test="country != 'UK'">postcode must exist if country is UK</sch:assert>
</sch:rule>
</schattern>
<sch:diagnostics>
<sch:diagnostic id="atomRefFormat">
<html>fff</html>
</sch:diagnostic>
</sch:diagnostics>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="senderAddress" type="addressType" />
<xsd:element name="recipientAddress" type="addressType" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="addressType">
<xsd:sequence>
<xsd:choice minOccurs="0">
<xsd:element name="postcode" type="xsd:string" />
<xsd:element name="zipcode" type="xsd:string" />
</xsd:choice>
<xsd:element name="country" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
---------------------------------------------------------------------
XML:
---------------------------------------------------------------------

<message>
<senderAddress> <!-- uses addressType -->
<postcode>123W 99U</postcode>
<country>UK</country>
</senderAddress>
<recipientAddress> <!-- uses addressType -->
<zipcode>12345</zipcode>
<country>US</country>
</recipientAddress>
</message>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Define custom XSD rules


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT