tags:

views:

56

answers:

2
+2  A: 

You need to define a complexType with a simpleContent:

    <xs:element name="AnElement">
      <xs:complexType>
        <xs:simpleContent>
          <xs:extension base="xs:int">
            <xs:attribute name="ID" type="xs:string" />
          </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    </xs:element>

That should do the trick. And I'm afraid that's the only way to achieve this. Is it really so bad??

UPDATE:
After your update, this is the XSD you'll need:

<xs:schema id="TheParentNode" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="TheParentNode">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="AnElement">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:int">
                <xs:attribute name="ID" type="xs:string" />
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

You are aware I hope that if you have the XML file open in Visual Studio, you can go to the "XML" menu and pick "Create schema" from it? That does give you a good start usually for your XSD files.

Marc

marc_s
Not bad, just trying to figure it out -- I'm pretty new to XSD.
JMarsch
Thanks again for your updates. I knew about the xsd support in Visual Studio (and I actually started from a reverse-engineered xsd (generated XSD from xml). We just need to modify some things that were not captured by the reverse engineering.
JMarsch
A: 

How about trying to set up the restriction option with regular express value? restriction and pattern xsd tags

 <xs:element name="AnElement">
     <xs:simpleType>
        <xs:restriction base="xs:integer">
        </xs:restriction>
     </xs:simpleType>
 </xs:element>

This means it allows only to have integers as zero or more digit.

I hope it helps.

Tiger.

Tiger
I wouldn't use something like that, seeing that you already have a xs:int base type in XSD. Why not just define a restriction based on xs:int? Makes more sense to me.
marc_s
@Tiger: why go through all that? -1.
John Saunders
John, I see; but, I was trying to help. I did not see where was wrong ? I might give wrong direction for that question ? I will appreciate if you can help me. Thank you.
Tiger
The xs:int type already restricts the content to digits only. No regular expression facet is necessary.
John Saunders
I agree with you for the xs:int. I was giving about further extension when I used the pattern tag such as if you want to limit the Five digits for integer, we can express as <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>. anyway, thank you for your comments.
Tiger
Four-digit int patterns can be expressed as <xs:restriction base="xs:int"><xs:length value="4"/></xs:restriction> - again: why use xs:string and regular expressions and make things more complicated than they need to be?
marc_s
That is true. I changed the xs:string. Thank you for your comments.
Tiger