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
    Posts
    1

    [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:
    Code:
    <email public="no">example@host.com</email>
    But I want to make sure that the adress is actually an email adress by checking it with a regular expression:
    Code:
    <xs:element name="email">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:pattern value="regex"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:element>
    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
    Posts
    1
    I had a similar issue... I ended up defining a type for the restriction, and then used the type in a simpleContent extension:

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

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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