1

I am using the xsd2code VS plug-in to create some data classes from a couple of xsd files and I'm having an issue where the namespace prefix for elements in the XSD do not appear in the generated XML files.

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>

generated 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>

The generated XML doesn't have the 'cmn' namespace prefix for the elements. Did I generate the classes incorrectly when I ran the plug-in? Is this something I need to change in the plug-ins source code?

I don't have a lot of experience working with XML so I apologize if this isn't enough information. If I'm missing something you'd need to know to help answer let me know! Thanks in advance :)

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65

1 Answers1

1

The xsd:schema element has an attribute named elementFormDefault, which determines whether elements local to a complex type are namespace-qualified or not. The default value is 'unqualified', which means that your elements AlternateItemCodes, TargetMarketList, etc. are not namespace-qualified at all. If you change the value to 'qualified', then local elements are in the target namespace of the schema document, i.e. in the namespace identified by the targetNamespace attribute of xsd:schema.

From your example, it looks as if you may not have a target namespace for the schema, and as if you may be expecting the namespace of the complex type to be taken on by the element; it won't be.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65