|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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> <sch attern 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> </sch attern></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> <sch attern 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> </sch attern><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> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Define custom XSD rules |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|