1

我正在使用 xsd2code VS 插件从几个 xsd 文件创建一些数据类,但我遇到了一个问题,即 XSD 中元素的命名空间前缀没有出现在生成的 XML 文件中。

XSD:

<xsd:complexType name="ProductMasterItemType">
  <xsd:sequence>
    <xsd:element ref="cmn:PrimaryItemCode"/>
    <xsd:element ref="cmn:NewPrimaryItemCode" minOccurs="0"/>
    <xsd:element ref="cmn:ProductGroupCode"/>
    <xsd:element ref="cmn:ProductStatus"/>
    <xsd:element ref="cmn:EffectiveDate" minOccurs="0"/>
    <xsd:element ref="cmn:RecordStatus"/>
    <xsd:element name="AlternateItemCodes"
                 type="cmn:AlternateItemCodeListType" 
                 minOccurs="0"/>
    <xsd:element name="TargetMarketList" 
                 type="mdx:TargetMarketListType" 
                 minOccurs="0"/>
    <xsd:element name="ItemInfoList" 
                 type="mdx:ItemInfoListType"/>
    <xsd:element name="PackagingInfoList" 
                 type="mdx:PackagingInfoListType" 
                 minOccurs="0"/>
  </xsd:sequence>
</xsd:complexType>

生成的 XML:

<ProductMasterItem>

  <PrimaryItemCode xmlns="urn:tracelink:mapper:sl:mdx:commontypes">
    <type>INTERNAL_MATERIAL_CODE</type>
    TestBOM5
  </PrimaryItemCode>  
  <ProductGroupCode xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
    >100</ProductGroupCode>
  <ProductStatus xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
    >Released</ProductStatus>
  <RecordStatus xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
    >Active</RecordStatus>
  <TargetMarketList>        
    <TargetMarket>
      <CountryMarket 
        xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >US</CountryMarket>
    </TargetMarket>
    <DeleteTargetMarket/>
  </TargetMarketList>
  <ItemInfoList>
    <ItemInfo>
      <LanguageCode xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >EN</LanguageCode>
      <ProductDescription 
        xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >Test BOM 5</ProductDescription>
      <DrugName xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >Nameofadrug</DrugName>
      <Manufacturer xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >- No Manufacturer -</Manufacturer>
      <Strength xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >verystrong</Strength>
      <DosageForm xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >15ml</DosageForm>
      <PackageSize xmlns="urn:tracelink:mapper:sl:mdx:commontypes"
        >40ml</PackageSize>
    </ItemInfo>
    <DeleteItemInfo/>
  </ItemInfoList>

生成的 XML 没有元素的“cmn”命名空间前缀。运行插件时是否错误地生成了类?这是我需要在插件源代码中更改的内容吗?

我没有很多使用 XML 的经验,因此如果信息不足,我深表歉意。如果我遗漏了您需要知道以帮助回答的内容,请告诉我!提前致谢 :)

4

1 回答 1

1

xsd:schema 元素有一个名为 elementFormDefault 的属性,它确定复杂类型的本地元素是否是命名空间限定的。默认值为“不合格”,这意味着您的元素 AlternateItemCodes、TargetMarketList 等根本不是命名空间限定的。如果将值更改为“qualified”,则本地元素位于模式文档的目标名称空间中,即位于由 xsd:schema 的 targetNamespace 属性标识的名称空间中。

从您的示例中,看起来您可能没有架构的目标名称空间,并且您可能期望元素采用复杂类型的名称空间;不会的。

于 2014-12-27T21:29:46.067 回答