XmlSchemaImport and XmlSchema.Write

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

    #1

    XmlSchemaImport and XmlSchema.Write

    I create a schema in memory and then I can write to a file fine. But
    as soon as I add an import element I get an error when it goes to write
    to the file.
    The error message is:

    The type System.Xml.Sche ma.XmlSchemaImp ort was not expected. Use the
    XmlInclude or SoapInclude attribute to specify types that are not known
    statically.

    What does this mean? Is there a limitation to when I can use
    <xs:importvs <xs:include>?
    And why does it occur when I go to write it out? Is the schema
    compiled at the time and is it looking to resolve the external schema?
    If so, that description doesn't seem very accurate.

    The following is the code that generates the schema (content gets
    filled in later):

    private XmlSchema GenerateBlankSc hema()
    {
    XmlSchema schema = new XmlSchema();
    schema.ElementF ormDefault = XmlSchemaForm.Q ualified;
    schema.Attribut eFormDefault = XmlSchemaForm.U nqualified;
    schema.TargetNa mespace =
    "http://schemas.infinit yinfo.com/coretypes";
    schema.Namespac es.Add("ii",
    "http://schemas.infinit yinfo.com/datatypes");
    XmlSchemaImport import = new XmlSchemaImport ();
    import.Namespac e =
    "http://schemas.infinit yinfo.com/datatypes";
    schema.Items.Ad d(import);
    return schema;
    }

    I've tried the overload that takes XmlNamespaceMan ager as the second
    parameter but same thing.

    Jiho

  • Zafar Abbas

    #2
    Re: XmlSchemaImport and XmlSchema.Write

    You should not add the XmlSchemaImport object to schema.items, rather to
    schema.Includes collection.

    "doughboy" <jihohan@gmail. comwrote in message
    news:1153243705 .173943.29920@h 48g2000cwc.goog legroups.com...
    I create a schema in memory and then I can write to a file fine. But
    as soon as I add an import element I get an error when it goes to write
    to the file.
    The error message is:
    >
    The type System.Xml.Sche ma.XmlSchemaImp ort was not expected. Use the
    XmlInclude or SoapInclude attribute to specify types that are not known
    statically.
    >
    What does this mean? Is there a limitation to when I can use
    <xs:importvs <xs:include>?
    And why does it occur when I go to write it out? Is the schema
    compiled at the time and is it looking to resolve the external schema?
    If so, that description doesn't seem very accurate.
    >
    The following is the code that generates the schema (content gets
    filled in later):
    >
    private XmlSchema GenerateBlankSc hema()
    {
    XmlSchema schema = new XmlSchema();
    schema.ElementF ormDefault = XmlSchemaForm.Q ualified;
    schema.Attribut eFormDefault = XmlSchemaForm.U nqualified;
    schema.TargetNa mespace =
    "http://schemas.infinit yinfo.com/coretypes";
    schema.Namespac es.Add("ii",
    "http://schemas.infinit yinfo.com/datatypes");
    XmlSchemaImport import = new XmlSchemaImport ();
    import.Namespac e =
    "http://schemas.infinit yinfo.com/datatypes";
    schema.Items.Ad d(import);
    return schema;
    }
    >
    I've tried the overload that takes XmlNamespaceMan ager as the second
    parameter but same thing.
    >
    Jiho
    >

    Comment

    • doughboy

      #3
      Re: XmlSchemaImport and XmlSchema.Write

      Thanks! That was it.

      Zafar Abbas wrote:
      You should not add the XmlSchemaImport object to schema.items, rather to
      schema.Includes collection.
      >
      "doughboy" <jihohan@gmail. comwrote in message
      news:1153243705 .173943.29920@h 48g2000cwc.goog legroups.com...
      I create a schema in memory and then I can write to a file fine. But
      as soon as I add an import element I get an error when it goes to write
      to the file.
      The error message is:

      The type System.Xml.Sche ma.XmlSchemaImp ort was not expected. Use the
      XmlInclude or SoapInclude attribute to specify types that are not known
      statically.

      What does this mean? Is there a limitation to when I can use
      <xs:importvs <xs:include>?
      And why does it occur when I go to write it out? Is the schema
      compiled at the time and is it looking to resolve the external schema?
      If so, that description doesn't seem very accurate.

      The following is the code that generates the schema (content gets
      filled in later):

      private XmlSchema GenerateBlankSc hema()
      {
      XmlSchema schema = new XmlSchema();
      schema.ElementF ormDefault = XmlSchemaForm.Q ualified;
      schema.Attribut eFormDefault = XmlSchemaForm.U nqualified;
      schema.TargetNa mespace =
      "http://schemas.infinit yinfo.com/coretypes";
      schema.Namespac es.Add("ii",
      "http://schemas.infinit yinfo.com/datatypes");
      XmlSchemaImport import = new XmlSchemaImport ();
      import.Namespac e =
      "http://schemas.infinit yinfo.com/datatypes";
      schema.Items.Ad d(import);
      return schema;
      }

      I've tried the overload that takes XmlNamespaceMan ager as the second
      parameter but same thing.

      Jiho

      Comment

      Working...