XmlSchema - validation trouble - .Net problem?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AlexS

    XmlSchema - validation trouble - .Net problem?

    Hello,

    I have error when reading schema using XmlSchema. Read and then .Compile:

    System.Xml.Sche ma.XmlSchemaExc eption: May not be nominated as the
    {substitution
    group affiliation} of any other declaration. An error occurred at , (11, 3).
    Schema compile error:
    System.Exceptio n: Schema error ---> System.Xml.Sche ma.XmlSchemaExc eption:
    May no
    t be nominated as the {substitution group affiliation} of any other
    declaration.
    An error occurred at , (11, 3).
    --- End of inner exception stack trace ---
    at XBRLMainClass.S chemaErrorHandl er(Object sender, ValidationEvent Args
    vea) i
    n c:\...\Main.cs: line 88
    at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption e,
    XmlSe
    verityType severity)
    at
    System.Xml.Sche ma.Compiler.Com pileSubstitutio nGroup(XmlSchem aSubstitutionG
    roup substitutionGro up)
    at System.Xml.Sche ma.Compiler.Com pileTo(SchemaIn fo schemaInfo)
    at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection collection,
    XmlNam
    eTable nameTable, SchemaNames schemaNames, ValidationEvent Handler
    validationEven
    tHandler, String targetNamespace , SchemaInfo schemaInfo, Boolean
    compileContentM
    odel, XmlResolver resolver)
    at System.Xml.Sche ma.XmlSchema.Co mpile(Validatio nEventHandler
    validationEvent
    Handler)

    When I look at failing line I see:

    <element id="pfsInc" name="Inc" type="xi:monIte mType"
    substitutionGro up="xi:item" />

    Element item is defined as

    <element name="item" type="anySimple Type" abstract="true" />

    What is wrong here?

    Why error message doesn't specify exacly which file at error occured?

    It doesn't matter if I specify abstract="true" or remove it.

    Anybody can help to find the answer? As per W3 it should work. However
    doesn't.

    Code I use is simple:

    fn=schemaFileNa meString;
    FileStream fs=new FileStream(fn,F ileMode.Open);

    XmlSchema xsd=null;

    try {

    xsd=XmlSchema.R ead(fs,new ValidationEvent Handler(SchemaE rrorHandler));

    }

    catch (Exception ex) {

    Console.WriteLi ne("Schema read
    exception:{0}{1 }",Environment. NewLine,ex.ToSt ring());

    Console.WriteLi ne("Schema read failed.");

    return;

    }

    finally {

    fs.Close();

    fs=null;

    }

    // compile schema

    try {

    xsd.Compile(new ValidationEvent Handler(SchemaE rrorHandler));

    }

    catch (Exception ex) {

    Console.WriteLi ne("Schema compile error:{0}{1}",

    Environment.New Line,

    ex.ToString());

    return;

    }

    Test schema file

    <?xml version="1.0"?>
    <schema targetNamespace ="instance" xmlns:xi="insta nce"
    xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefa ult="qualified" >
    <simpleType name="monT">
    <restriction base="decimal"/>
    </simpleType>
    <simpleType name="shaT">
    <restriction base="decimal">
    <minInclusive value="0"/>
    </restriction>
    </simpleType>
    <element name="itemAbs" type="anySimple Type" />
    <!-- element name="item" type="anySimple Type"
    substitutionGro up="xi:itemAbs " / -->
    <element name="Inc" type="xi:monT" substitutionGro up="xi:itemAbs "/>
    <element name="Dec" type="xi:shaT" />
    </schema>

    Anybody can point me in right direction? How can I define substitution group
    in a way compatible with .Net?

    Thanks!
    Alex


  • Dare Obasanjo [MSFT]

    #2
    Re: XmlSchema - validation trouble - .Net problem? - or w3.org xsd docs problem?

    This schema is NOT valid. There are several things wrong with it such as the
    fact that you reference complex types such as "xs:annotat ed" and "xs:facet"
    which are not defined in an imported schema for the
    "http://www.w3.org/2001/XMLSchema" namespace. However, even if you did do
    this I would suggest not trying to define interactions between user-defined
    types and types defined in the schema for Schema because the schema for
    Schema isn't actually a valid schema according to the rules specified in the
    W3C XML Schema recommendation.

    --
    This posting is provided "AS IS" with no warranties, and confers no rights.


    "AlexS" <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote in message
    news:O5kZaISVDH A.1480@tk2msftn gp13.phx.gbl...[color=blue]
    > Further to previous.
    >
    > I took example of subsitutionGrou p definition from 3.3.2 at
    > http://www.w3.org/TR/xmlschema-1/#cElement_Declarations.
    >
    > Test file I use is:
    >
    > <xs:schema targetNamespace ="schema" xmlns:x="schema "
    > xmlns:xs="http://www.w3.org/2001/XMLSchema">
    > <xs:complexTy pe name="facet">
    > <xs:complexCont ent>
    > <xs:extension base="xs:annota ted">
    > <xs:attribute name="value" use="required"/>
    > </xs:extension>
    > </xs:complexConte nt>
    > </xs:complexType>
    >
    > <xs:element name="facet" type="xs:facet" abstract="true"/>
    >
    > <xs:element name="encoding" substitutionGro up="xs:facet">
    > <xs:complexType >
    > <xs:complexCont ent>
    > <xs:restricti on base="xs:facet" >
    > <xs:sequence>
    > <xs:element ref="annotation " minOccurs="0"/>
    > </xs:sequence>
    > <xs:attribute name="value" type="xs:encodi ngs"/>
    > </xs:restriction>
    > </xs:complexConte nt>
    > </xs:complexType>
    > </xs:element>
    >
    > <xs:element name="period" substitutionGro up="xs:facet">
    > <xs:complexType >
    > <xs:complexCont ent>
    > <xs:restricti on base="xs:facet" >
    > <xs:sequence>
    > <xs:element ref="annotation " minOccurs="0"/>
    > </xs:sequence>
    > <xs:attribute name="value" type="xs:durati on"/>
    > </xs:restriction>
    > </xs:complexConte nt>
    > </xs:complexType>
    > </xs:element>
    >
    > <xs:complexTy pe name="datatype" >
    > <xs:sequence>
    > <xs:element ref="facet" minOccurs="0" maxOccurs="unbo unded"/>
    > </xs:sequence>
    > <xs:attribute name="name" type="xs:NCName " use="optional"/>
    > </xs:complexType>
    >
    > </xs:schema>
    >
    > .Net ReadXMLSchema or XmlSchema.Compi le fails with:
    > System.Xml.Sche ma.XmlSchemaExc eption: Reference to undeclared substitution
    > group
    > affiliation. An error occurred at , (13, 3).
    > Schema compile error:
    > System.Exceptio n: Schema error ---> System.Xml.Sche ma.XmlSchemaExc eption:
    > Refere
    > nce to undeclared substitution group affiliation. An error occurred at ,
    > (13, 3)
    > .
    > --- End of inner exception stack trace ---
    > at XBRLMainClass.S chemaErrorHandl er(Object sender, ValidationEvent Args
    > vea) i
    > n c:\...\Main.cs: line 88
    > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption e,
    > XmlSe
    > verityType severity)
    > at
    > System.Xml.Sche ma.Compiler.Com pileSubstitutio nGroup(XmlSchem aSubstitutionG
    > roup substitutionGro up)
    > at System.Xml.Sche ma.Compiler.Com pileTo(SchemaIn fo schemaInfo)
    > at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection collection,
    > XmlNam
    > eTable nameTable, SchemaNames schemaNames, ValidationEvent Handler
    > validationEven
    > tHandler, String targetNamespace , SchemaInfo schemaInfo, Boolean
    > compileContentM
    > odel, XmlResolver resolver)
    > at System.Xml.Sche ma.XmlSchema.Co mpile(Validatio nEventHandler
    > validationEvent
    > Handler).
    >
    > And validator at
    > http://apps.gotdotnet.com/xmltools/x...r/Default.aspx fails in
    > different way:
    > Reference to undeclared substitution group affiliation. An error occurred[/color]
    at[color=blue]
    > , (13, 3).
    > Undefined complexType 'http://www.w3.org/2001/XMLSchema:annot ated' is used
    > as a base for complex type extension". An error occurred at , (5, 5).
    > Type 'http://www.w3.org/2001/XMLSchema:facet ' is not declared. An error
    > occurred at , (11, 3).
    > Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet ' is used as[/color]
    a[color=blue]
    > base for complex type restriction". An error occurred at , (16, 6).
    > Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet ' is used as[/color]
    a[color=blue]
    > base for complex type restriction". An error occurred at , (29, 6).
    > The 'facet' element is not declared. An error occurred at , (41, 5).
    >
    > What's the problem?
    >
    > Is the sample in w3.org docs wrong? Who is right, .Net validator,[/color]
    gotdotnet[color=blue]
    > validator or w3.org?
    >
    > Can anybody point in right direction? Or provide a sample of xsd file with
    > substitution groups working with .Net validation?
    >
    >
    > PLEASE!!!!
    >
    >
    >[/color]


    Comment

    • AlexS

      #3
      Re: XmlSchema - validation trouble - .Net problem? - or w3.org xsd docs problem?

      Dare,

      here are 2 examples of schema: first one is validated Ok, and second one
      fails. I have to process original schema as in second one. I can't change it
      and I did not create it. And creators insist that schema is Ok.

      The difference is that second schema uses substitutionGro up. And .net
      validator fails over it.
      At the same time, second variant is validated Ok by
      http://apps.gotdotnet.com/xmltools/xsdvalidator/.

      variant which passes XmlSchema.Compi le:
      <schema targetNamespace ="sch" xmlns:xs="sch"
      xmlns="http://www.w3.org/2001/XMLSchema" >

      <simpleType name="monetary" >
      <restriction base="decimal"/>
      </simpleType>
      <simpleType name="shares">
      <restriction base="decimal">
      <minInclusive value="0"/>
      </restriction>
      </simpleType>

      <element name="item-abs" type="decimal" abstract="true" />

      <element id="iascf-pfs_WorkProgres s" name="WorkProgr ess"
      type="xs:moneta ry" />
      <element id="iascf-pfs_WarrantyPro visionNonCurren t"
      name="WarrantyP rovisionNonCurr ent" type="xs:moneta ry" />
      </schema>

      Variant, which fails in XmlSchema.Compi le and passes in xsdvalidator:
      <schema targetNamespace ="sch" xmlns:xs="sch"
      xmlns="http://www.w3.org/2001/XMLSchema" >

      <simpleType name="monetary" >
      <restriction base="decimal"/>
      </simpleType>
      <simpleType name="shares">
      <restriction base="decimal">
      <minInclusive value="0"/>
      </restriction>
      </simpleType>

      <element name="item-abs" type="decimal" abstract="true" />

      <element id="iascf-pfs_WorkProgres s" name="WorkProgr ess"
      type="xs:moneta ry" substitutionGro up="xs:item-abs"/>
      <element id="iascf-pfs_WarrantyPro visionNonCurren t"
      name="WarrantyP rovisionNonCurr ent" type="xs:moneta ry"
      substitutionGro up="xs:item-abs" />
      </schema>

      When I check what w3.org says on subtitution groups - I don't see why second
      schema should fail.

      Can you explain (or point out where I can see explanation for this) why
      second variant fails in XmlSchema.Compi le?

      To me it looks like bug in .Net. Or where?

      Sorry, if my previous example was not completely Ok. I hope this one is more
      clear

      Btw, would you mind to explain a bit what you mean by "...because the schema
      for[color=blue]
      > Schema isn't actually a valid schema according to the rules specified in[/color]
      the[color=blue]
      > W3C XML Schema recommendation. "?[/color]


      Rgds
      Alex

      "Dare Obasanjo [MSFT]" <dareo@online.m icrosoft.com> wrote in message
      news:3f2573cc$1 @news.microsoft .com...[color=blue]
      > This schema is NOT valid. There are several things wrong with it such as[/color]
      the[color=blue]
      > fact that you reference complex types such as "xs:annotat ed" and[/color]
      "xs:facet"[color=blue]
      > which are not defined in an imported schema for the
      > "http://www.w3.org/2001/XMLSchema" namespace. However, even if you did do
      > this I would suggest not trying to define interactions between[/color]
      user-defined[color=blue]
      > types and types defined in the schema for Schema because the schema for
      > Schema isn't actually a valid schema according to the rules specified in[/color]
      the[color=blue]
      > W3C XML Schema recommendation.
      >
      > --
      > This posting is provided "AS IS" with no warranties, and confers no[/color]
      rights.[color=blue]
      >
      >
      > "AlexS" <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote in message
      > news:O5kZaISVDH A.1480@tk2msftn gp13.phx.gbl...[color=green]
      > > Further to previous.
      > >
      > > I took example of subsitutionGrou p definition from 3.3.2 at
      > > http://www.w3.org/TR/xmlschema-1/#cElement_Declarations.
      > >
      > > Test file I use is:
      > >
      > > <xs:schema targetNamespace ="schema" xmlns:x="schema "
      > > xmlns:xs="http://www.w3.org/2001/XMLSchema">
      > > <xs:complexTy pe name="facet">
      > > <xs:complexCont ent>
      > > <xs:extension base="xs:annota ted">
      > > <xs:attribute name="value" use="required"/>
      > > </xs:extension>
      > > </xs:complexConte nt>
      > > </xs:complexType>
      > >
      > > <xs:element name="facet" type="xs:facet" abstract="true"/>
      > >
      > > <xs:element name="encoding" substitutionGro up="xs:facet">
      > > <xs:complexType >
      > > <xs:complexCont ent>
      > > <xs:restricti on base="xs:facet" >
      > > <xs:sequence>
      > > <xs:element ref="annotation " minOccurs="0"/>
      > > </xs:sequence>
      > > <xs:attribute name="value" type="xs:encodi ngs"/>
      > > </xs:restriction>
      > > </xs:complexConte nt>
      > > </xs:complexType>
      > > </xs:element>
      > >
      > > <xs:element name="period" substitutionGro up="xs:facet">
      > > <xs:complexType >
      > > <xs:complexCont ent>
      > > <xs:restricti on base="xs:facet" >
      > > <xs:sequence>
      > > <xs:element ref="annotation " minOccurs="0"/>
      > > </xs:sequence>
      > > <xs:attribute name="value" type="xs:durati on"/>
      > > </xs:restriction>
      > > </xs:complexConte nt>
      > > </xs:complexType>
      > > </xs:element>
      > >
      > > <xs:complexTy pe name="datatype" >
      > > <xs:sequence>
      > > <xs:element ref="facet" minOccurs="0" maxOccurs="unbo unded"/>
      > > </xs:sequence>
      > > <xs:attribute name="name" type="xs:NCName " use="optional"/>
      > > </xs:complexType>
      > >
      > > </xs:schema>
      > >
      > > .Net ReadXMLSchema or XmlSchema.Compi le fails with:
      > > System.Xml.Sche ma.XmlSchemaExc eption: Reference to undeclared[/color][/color]
      substitution[color=blue][color=green]
      > > group
      > > affiliation. An error occurred at , (13, 3).
      > > Schema compile error:
      > > System.Exceptio n: Schema error --->[/color][/color]
      System.Xml.Sche ma.XmlSchemaExc eption:[color=blue][color=green]
      > > Refere
      > > nce to undeclared substitution group affiliation. An error occurred at ,
      > > (13, 3)
      > > .
      > > --- End of inner exception stack trace ---
      > > at XBRLMainClass.S chemaErrorHandl er(Object sender,[/color][/color]
      ValidationEvent Args[color=blue][color=green]
      > > vea) i
      > > n c:\...\Main.cs: line 88
      > > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption[/color][/color]
      e,[color=blue][color=green]
      > > XmlSe
      > > verityType severity)
      > > at
      > >[/color][/color]
      System.Xml.Sche ma.Compiler.Com pileSubstitutio nGroup(XmlSchem aSubstitutionG[color=blue][color=green]
      > > roup substitutionGro up)
      > > at System.Xml.Sche ma.Compiler.Com pileTo(SchemaIn fo schemaInfo)
      > > at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection[/color][/color]
      collection,[color=blue][color=green]
      > > XmlNam
      > > eTable nameTable, SchemaNames schemaNames, ValidationEvent Handler
      > > validationEven
      > > tHandler, String targetNamespace , SchemaInfo schemaInfo, Boolean
      > > compileContentM
      > > odel, XmlResolver resolver)
      > > at System.Xml.Sche ma.XmlSchema.Co mpile(Validatio nEventHandler
      > > validationEvent
      > > Handler).
      > >
      > > And validator at
      > > http://apps.gotdotnet.com/xmltools/x...r/Default.aspx fails in
      > > different way:
      > > Reference to undeclared substitution group affiliation. An error[/color][/color]
      occurred[color=blue]
      > at[color=green]
      > > , (13, 3).
      > > Undefined complexType 'http://www.w3.org/2001/XMLSchema:annot ated' is[/color][/color]
      used[color=blue][color=green]
      > > as a base for complex type extension". An error occurred at , (5, 5).
      > > Type 'http://www.w3.org/2001/XMLSchema:facet ' is not declared. An error
      > > occurred at , (11, 3).
      > > Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet ' is used[/color][/color]
      as[color=blue]
      > a[color=green]
      > > base for complex type restriction". An error occurred at , (16, 6).
      > > Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet ' is used[/color][/color]
      as[color=blue]
      > a[color=green]
      > > base for complex type restriction". An error occurred at , (29, 6).
      > > The 'facet' element is not declared. An error occurred at , (41, 5).
      > >
      > > What's the problem?
      > >
      > > Is the sample in w3.org docs wrong? Who is right, .Net validator,[/color]
      > gotdotnet[color=green]
      > > validator or w3.org?
      > >
      > > Can anybody point in right direction? Or provide a sample of xsd file[/color][/color]
      with[color=blue][color=green]
      > > substitution groups working with .Net validation?
      > >
      > >
      > > PLEASE!!!!
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...