tags:

views:

57

answers:

3

Hi,

I have a simple XSD:

    <xs:element name="config">
    <xs:complexType>
      <xs:sequence minOccurs="1" maxOccurs="unbounded">
        <xs:element name="group" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
    </xs:element>

On my xml file i put this:

<config>
<group></group>
<a></a> 
</config>

How block the insertion of <a> tag on my xml?

Obs: group appears on auto-complete on my C# xml editor!!!

+1  A: 

You cannot "block" the insertion of the <a> unless you write a XML editor yourself which would understand and interpret the XSD schema on the fly.

What you can do is validate the XML created against the schema and refuse it, if it's not valid.

Marc

marc_s
MarcI thinks this is not true!!When I use NHibernate XSD a receive an error on Visual Studio error list talking about a invalid elements.But i not found the especific 'tag or attribute' that perfomr this validation.Exemple:Try to use a tag named 'anything' on Nhibernate Xml Mapping file and you receive an error on VisualStudio ErrorList!!Thanks for Replay!!
CrazyJoe
Visual studio will automatically validate XML when it knows about the schema. Chances are that NHibernate installs its schema into VS.You can see what schemas are being validated against when in an XML file by going to XML -> Schemas (if memory serves).
Oded
Visual studio validate my xml correctly (I think) , because dthe config and group thag appers o auto-complete. Resuming: the Visual Studio already now about config and group tags.
CrazyJoe
Yes - as I said, if you use Visual Studio or write your own editor which can validate a XML based on a XML schema, you can validate on the fly and provide feedback - but you can't really "block" anyone from typing a wrong invalid XML document..... (you can only highlight that it's wrong)
marc_s
A: 

Sounds to me like that tag you'd like to exclude should be a child of the "config" tag, just like group. If it has a relationship with "config", and should only appear if its parent does, you need to express it.

duffymo
how i express that '<a>' tag is invaid element on config tag?
CrazyJoe
A: 

Problem Resolved!!

Is a error on my Visual Studio Express Edition

The Visual Studio 2008 (Full Version) process XSD correctly!!

Thanks for all!!

CrazyJoe