Hi Malintha,

Yes. This is fine. Another workaround to achieve this is to define set of
values that can be accepted by the restriction. In here we can ignore $.
i.e if $ exists it will throw SAX exception.

                <xs:element name="Name">
                     <xs:annotation>
                       <xs:documentation>Product Name</xs:documentation>
                     </xs:annotation>
                    <xs:simpleType>
                      <xs:restriction base="xs:string">
                        <xs:pattern value="[a-zA-Z0-9_.'
!@#%^*()_+={}|/:;,>?/`~ ]*"/>
                      </xs:restriction>
                    </xs:simpleType>
                </xs:element>

Regards


On Wed, Oct 30, 2013 at 11:20 AM, Malintha Adikari <[email protected]>wrote:

> Hi Dimuthu,
>
> Yes we can do this. As an example consider following XML and the related
> XSD:
>
> XML:
>
> <parent name="abc">
>
> </parent>
>
> XSD:
>
> <xs:schema attributeFormDefault="unqualified"
> elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema
> ">
>     <xs:element name="parent">
>         <xs:complexType>
>             <xs:simpleContent>
>                 <xs:extension base="xs:string">
>                     <xs:attribute type="myAttribute" name="name"/>
>                 </xs:extension>
>             </xs:simpleContent>
>         </xs:complexType>
>     </xs:element>
>
>     <xs:simpleType name="myAttribute">
>         <xs:restriction base="xs:string">
>             <xs:pattern value="[^$]*"/>
>         </xs:restriction>
>     </xs:simpleType>
> </xs:schema>
>
>
> This is checking for the "$" character in the name attribute of the parent
> element and return an SAXException if it found that character. Hope this
> will work for you
>
> Thanks,
> Malintha Adikari
>
>
> On Wed, Oct 30, 2013 at 10:31 AM, Dimuthu De Lanerolle 
> <[email protected]>wrote:
>
>> Hi All,
>>
>> I need to validate some xml files against their respective xsd files. In
>> here, I need to validate some attribute values against the schema. Is there
>> any way to impose a restriction on an attribute value to check whether the
>> actual value of the attribute contains a special character like '$'. i.e in
>> case the attribute value of the .xml file contains '$' , schema validation
>> should throw a SAXException. Does anyone know ?
>>
>> Regards
>>
>>
>> --
>> Dimuthu De Lanerolle
>> Software Engineer
>> WSO2 Inc.
>> lean . enterprise . middlewear.
>> http://wso2.com/
>> Tel. : +94 11 2145345  Fax : +94 11 2145300  email : [email protected]
>>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>


-- 
Dimuthu De Lanerolle
Software Engineer
WSO2 Inc.
lean . enterprise . middlewear.
http://wso2.com/
Tel. : +94 11 2145345  Fax : +94 11 2145300  email : [email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to