DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: [XML Schema] Element with restriction and attribute

  1. #1
    Join Date
    Sep 2005

    [XML Schema] Element with restriction and attribute

    Hello, I have the following problem and I really hope someone here can help me.

    I am trying to write an XML Schema to validate some XML and the problem is that I can't seem to get an attribute on an element that has a restriction.

    I want to validate this:
    <email public="no"></email>
    But I want to make sure that the adress is actually an email adress by checking it with a regular expression:
    <xs:element name="email">
        <xs:restriction base="xs:string">
          <xs:pattern value="regex"/>
    But I also want the attribute. Problem is, I can't add it to a simpleType, so I need to give "email" a complexType. But doing that, restricts me from setting a restriction on the content of the element, because the parser says I can't use the xs:string-base for a restriction in a complexType.

    I have searched for the answer to my question for a couple of days now and I still haven't found it. I really can't believe that nobody knows a solution, because I would think that it is kind of common to have something similar to what I want. Anyway, I hope someone will be able to help. Thanks!
    Last edited by CyberByte; 09-01-2005 at 07:10 PM. Reason: Turned on email notification

  2. #2
    Join Date
    Oct 2005
    I had a similar issue... I ended up defining a type for the restriction, and then used the type in a simpleContent extension:

    <!-- Type definition -->
    <xs:simpleType name="emailString">
    	<xs:restriction base="xs:string">
    		<xs:pattern value="regex" />
    <!-- Element -->
    <xs:element name="email">
    			<xs:extension base="emailString">
    				<xs:attribute name="public" type="xs:boolean" />

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center