【问题标题】:XSD can't get external namespaceXSD 无法获取外部命名空间
【发布时间】:2017-11-03 19:06:01
【问题描述】:

我想根据 XSD 文件生成 C# 代码,但是有问题 架构、VS 和 xsd.exe 中的 namspaces 显示在一个特定命名空间中定义的所有类型的警告。我认为这实际上可能是错误的,但我在 XSD Diagram(用于打开此类文件的程序)中打开了 XSD 文件,它正确显示了每种类型,即使它们位于同一个命名空间中。

有问题的命名空间是 xmlns:curr="http://www.currenda.pl/epu"

<xsd:schema xmlns:curr="http://www.currenda.pl/epu" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.currenda.pl/epu" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xml:lang="pl">
  <xsd:element name="Pozwy">
    <xsd:annotation>
      <xsd:documentation>Paczka pozwów w elektronicznym postępowaniu upominawczym</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="PozewEPU" type="curr:PozewEPU" maxOccurs="unbounded" />
      </xsd:sequence>
      <xsd:attribute name="OznaczeniePaczki" type="curr:typNazwa60" use="required">
        <xsd:annotation>
          <xsd:documentation>Oznaczenie paczki nadawane przez powoda masowego używane jako kryterium wyszukiwania i rozliczania opłat</xsd:documentation>
        </xsd:annotation>
      </xsd:attribute>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="PozewEPU">
    <xsd:annotation>
      <xsd:documentation>Pozew inicjujący sprawę w elektronicznym postępowaniu upominawczym</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="Oswiadczenie" type="xsd:string" minOccurs="0">
        <xsd:annotation>
          <xsd:documentation>Przyjmuje wartości tak/nie</xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="Adresat" type="curr:typAdresat" />
      <xsd:element name="SadWlasciwy" type="curr:typAdresat" minOccurs="0" />
      <xsd:element name="OsobaSkladajaca" type="curr:typSkladajacy" />
      <xsd:element name="ListaPowodow" type="curr:typListaPowodow" />
      <xsd:element name="ListaPozwanych" type="curr:typListaPozwanych" />
      <xsd:element name="SprawaWgPowoda" minOccurs="0" type="curr:typNazwa60">
        <xsd:annotation>
          <xsd:documentation>Sygnatura / oznaczenie sprawy nadane przez powoda </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="WartoscSporu" type="xsd:decimal">
        <xsd:annotation>
          <xsd:documentation>Suma wartości roszczeń zdefiniowanych na liście roszczeń wyrażona w PLN</xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="OplataSadowa" type="curr:typOplata" />
      <xsd:element name="KosztyZastepstwa" type="curr:typKoszty" />
      <xsd:element name="InneKoszty" type="curr:typKoszty" minOccurs="0" />
      <xsd:element name="RachunekDoZwrotuOplat" type="curr:typRachunekDoZwrotuOplat" >
        <xsd:annotation>
          <xsd:documentation>Element dla numeru oraz nazwy właściciela rachunku do zwrotu opłat sądowych</xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="ListaRoszczen" type="curr:typLista" />
      <xsd:element name="ListaDowodow" type="curr:typListaDowodow" minOccurs="0" />
      <xsd:element name="InneRoszczenia" type="curr:typTekstowy" minOccurs="0" />
      <xsd:element name="Uzasadnienie" type="curr:typTekstowy" />
    </xsd:sequence>
    <xsd:attribute name="ID" type="xsd:unsignedLong" use="required">
      <xsd:annotation>
        <xsd:documentation>Unikalny w ramach paczki numer ID pozwu </xsd:documentation>
      </xsd:annotation>
    </xsd:attribute>
    <xsd:attribute name="version" type="curr:typNazwa10" use="required" fixed="1.0">
      <xsd:annotation>
        <xsd:documentation>Oznaczenie wersji formatu </xsd:documentation>
      </xsd:annotation>
    </xsd:attribute>
    <xsd:attribute name="dataZlozenia" type="curr:typData" use="required" />
  </xsd:complexType>
</xsd:schema>

在错误中说:类型 [...] 未声明

我将不胜感激 提前致谢

编辑:具有数据类型的 xsd 的一部分(太大而无法将其全部粘贴

<xsd:schema xmlns:curr="http://www.e-sad.gov.pl/epu" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.e-sad.gov.pl/epu" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.0" xml:lang="pl">
  <xsd:simpleType name="typNIP">
    <xsd:annotation>
      <xsd:documentation>Numer NIP</xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="([1-9]((\d[1-9])|([1-9]\d))\d{7})|(^$)" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="typPESEL">
    <xsd:annotation>
      <xsd:documentation>Definicja numeru PESEL</xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[0-9]{11}" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="typKRS">
    <xsd:annotation>
      <xsd:documentation>Definicja KRS </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[0-9]{10}" />
    </xsd:restriction>
  </xsd:simpleType>

【问题讨论】:

  • 您的 XSD 确实没有定义 typNazwa10 类型、typData 类型或除 PozewEPU 之外的任何类型。它们是在其他文件中定义的吗?
  • 其实我是 xml 的新手,所以我认为它们是在那个命名空间中声明的,但是我现在看到我也有这些类型的 xsd,我应该如何附加它?
  • 我相信您可以通过在上面的 XSD 中添加 &lt;xsd:import namespace="http://www.currenda.pl/epu" schemaLocation="theOtherFileNameGoesHere.xsd" /&gt; 来做到这一点。
  • 不幸的是,当我添加此行时,我收到 3 个警告:“导入的命名空间属性与 元素的 targetNamespace 元素的实际值不匹配。” “无法识别 schemaLocation 属性”和一个关于 System.Security.Permissions.FileIOPermission 的奇怪警告
  • 啊,我没注意到这也是xsd 的命名空间。怎么样:&lt;xsd:include schemaLocation="theOtherFileNameGoesHere.xsd" /&gt;

标签: c# xml xsd namespaces


【解决方案1】:

您收到错误是因为您的 XSD 使用了在别处定义的类型。 xsd.exe 需要所有定义才能工作。根据您在 cmets 中所说的内容,听起来您需要通过在主文件中像这样引用另一个文件来包含另一个文件:

<xsd:include schemaLocation="theOtherFileNameGoesHere.xsd" />

【讨论】:

    猜你喜欢
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 2023-04-09
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多