Suman Shekhar
Suman Shekhar

Reputation: 1

Issue while validating a XML containing a namespace against a XSD

I am trying to validate an XML against an XSD. The XML contains a namespace declaration in the root element:

xmlns="http://www.sample.com/itemfile"

Currently when I am validating I am getting an error:

Src-resolve.4.1: Error Resolving Component 'pos_integer_type'. It Was Detected That 'pos_integer_type' Has No Namespace, But Components With No Target Namespace Are Not Referenceable From Schema Document 'null'. If 'pos_integer_type' Is Intended To Have A Namespace, Perhaps A Prefix Needs To Be Provided. If It Is Intended That 'pos_integer_type' Has No Namespace, Then An 'import' Without A "namespace" Attribute Should Be Added To 'null'.

If I remove xmlns="http://www.sample.com/itemfile" from the XML file, it works with the existing xsd.

I am not getting what exactly is going wrong here. Please guide me on how I can modify the existing xsd and validate the XML containing the namespace.

These two similar existing issues didn't help much as I am doing exactly what they are referring to:

How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

xmlns, xmlns:xsi, xsi:schemaLocation, and targetNamespace?

You can validate the XML file online at https://www.freeformatter.com/xml-validator-xsd.html

I really appreciate any help you can provide.

The XML Document

<?xml version="1.0" encoding="UTF-8"?>
<ItemFileDelta xmlns="http://www.sample.com/itemfile">
    <item action="C">
        <mds_fam_id>200150068</mds_fam_id>
        <item_nbr>50099609</item_nbr>
        <consumer_item_nbr>3720170</consumer_item_nbr>
        <upc_nbr>19473513596</upc_nbr>
        <case_upc_nbr>1019473513596</case_upc_nbr>
        <whpk_upc_nbr>1019473513596</whpk_upc_nbr>
        <vendor_stock_id>HMY99</vendor_stock_id>
        <acctg_dept_nbr>7</acctg_dept_nbr>
        <dept_nbr>7</dept_nbr>
        <subclass_nbr>0</subclass_nbr>
        <fineline_nbr>2040</fineline_nbr>
        <product_nbr>21765900</product_nbr>
        <brand_id>319731</brand_id>
        <vendor_nbr>857474</vendor_nbr>
        <vendor_dept_nbr>7</vendor_dept_nbr>
        <vendor_seq_nbr>0</vendor_seq_nbr>
        <item1_desc>UNO FLEX</item1_desc>
        <item2_desc/>
        <shlflbl1_colr_desc>MULTI</shlflbl1_colr_desc>
        <shlflbl2_size_desc>EA</shlflbl2_size_desc>
        <upc_desc>UNO FLEX</upc_desc>
        <signing_desc>UNO FLEX CARD GAME</signing_desc>
        <item_length_qty>0.750</item_length_qty>
        <item_width_qty>3.633</item_width_qty>
        <item_height_qty>5.685</item_height_qty>
        <item_dim_uom_code>IN</item_dim_uom_code>
        <item_weight_qty>0.3530</item_weight_qty>
        <item_weight_uom_cd>LB</item_weight_uom_cd>
        <whpk_qty>12</whpk_qty>
        <whpk_length_qty>8.144</whpk_length_qty>
        <whpk_width_qty>5.503</whpk_width_qty>
        <whpk_height_qty>6.250</whpk_height_qty>
        <whpk_dim_uom_code>IN</whpk_dim_uom_code>
        <whpk_weight_qty>4.8943</whpk_weight_qty>
        <whpk_weight_uom_cd>LB</whpk_weight_uom_cd>
        <vnpk_qty>12</vnpk_qty>
        <vnpk_length_qty>8.144</vnpk_length_qty>
        <vnpk_width_qty>5.503</vnpk_width_qty>
        <vnpk_height_qty>6.250</vnpk_height_qty>
        <vnpk_dim_uom_code>IN</vnpk_dim_uom_code>
        <vnpk_cube_qty>0.162</vnpk_cube_qty>
        <vnpk_cube_uom_cd>CF</vnpk_cube_uom_cd>
        <vnpk_weight_qty>4.8943</vnpk_weight_qty>
        <vnpk_weight_uom_cd>LB</vnpk_weight_uom_cd>
        <vnpk_cspk_code>C</vnpk_cspk_code>
        <pallet_ti_qty>42</pallet_ti_qty>
        <pallet_hi_qty>8</pallet_hi_qty>
        <whse_align_type_cd>AS</whse_align_type_cd>
        <crush_factor_code>2</crush_factor_code>
        <conveyable_ind>N</conveyable_ind>
        <temp_sensitive_ind>N</temp_sensitive_ind>
        <cust_base_rtl_amt>9.97</cust_base_rtl_amt>
        <base_unit_rtl_amt>9.97</base_unit_rtl_amt>
        <unit_cost_amt>5.6600</unit_cost_amt>
        <discount_ind>Y</discount_ind>
        <proj_yr_sale_qty>16494</proj_yr_sale_qty>
        <sell_qty>1.0000</sell_qty>
        <sell_uom_code>EA</sell_uom_code>
        <price_comp_uom_cd/>
        <item_status_code>A</item_status_code>
        <item_ord_eff_date>2023-02-27</item_ord_eff_date>
        <item_type_code>33</item_type_code>
        <repl_subtype_code>0</repl_subtype_code>
        <item_rplnshbl_ind>Y</item_rplnshbl_ind>
        <cancel_whn_out_ind>N</cancel_whn_out_ind>
        <variable_wt_ind>N</variable_wt_ind>
        <backrm_scale_ind>N</backrm_scale_ind>
        <whse_area_code>6</whse_area_code>
        <online_ind>N</online_ind>
        <store_ind>Y</store_ind>
        <replenish_unit_ind>N</replenish_unit_ind>
        <guar_sales_ind>Y</guar_sales_ind>
        <vnpk_weight_fmt_cd>F</vnpk_weight_fmt_cd>
        <origin_country_cd>CN</origin_country_cd>
        <marshal_id>61</marshal_id>
        <mbm_code>M</mbm_code>
    </item>
</ItemFileDelta>

XSD Document

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"   targetNamespace="http://www.sample.com/itemfile"  elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:element name="ItemFileDelta" >
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="mds_fam_id" type="pos_integer_type"/>
                            <xsd:element name="sku_id" type="xsd:string" minOccurs="0"/>
                            <xsd:element name="Product_id" type="xsd:string" minOccurs="0"/>
                            <xsd:group ref="itemInfo" minOccurs="0"/>
                        </xsd:sequence>
                        <xsd:attribute name="action" type="action_type" use="required"/>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:group name="itemInfo">
        <xsd:sequence>
            <xsd:element name="item_nbr" type="pos_integer_type"/>
            <xsd:element name="consumer_item_nbr" type="pos_integer_type"/>
            <xsd:element name="upc_nbr" type="upc_nbr_type"/>
            <xsd:element name="case_upc_nbr" type="upc_nbr_type" minOccurs="0"/>
            <xsd:element name="whpk_upc_nbr" type="upc_nbr_type" minOccurs="0"/>
            <xsd:element name="vendor_stock_id" type="vendor_stock_id_type"/>
            <xsd:element name="plu_nbr" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="acctg_dept_nbr" type="dept_nbr_type" minOccurs="0"/>
            <xsd:element name="dept_nbr" type="dept_nbr_type"/>
            <xsd:element name="subclass_nbr" type="pos_smallint_type"/>
            <xsd:element name="fineline_nbr" type="pos_smallint_type"/>
            <xsd:element name="product_nbr" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="brand_id" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="vendor_nbr" type="vendor_nbr_type"/>
            <xsd:element name="vendor_dept_nbr" type="vendor_dept_nbr_type"/>
            <xsd:element name="vendor_seq_nbr" type="vendor_seq_nbr_type"/>
            <xsd:element name="item1_desc" type="item_desc_type"/>
            <xsd:element name="item2_desc" type="item_desc_type" minOccurs="0"/>
            <xsd:element name="shlflbl1_colr_desc" type="shelf_label_desc_type" minOccurs="0"/>
            <xsd:element name="shlflbl2_size_desc" type="shelf_label_desc_type" minOccurs="0"/>
            <xsd:element name="upc_desc" type="upc_desc_type"/>
            <xsd:element name="signing_desc" type="signing_desc_type"/>
            <xsd:element name="item_length_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="item_width_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="item_height_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="item_dim_uom_code" type="dim_uom_code_type" minOccurs="0"/>
            <xsd:element name="item_weight_qty" type="weight_qty_type" minOccurs="0"/>
            <xsd:element name="item_weight_uom_cd" type="weight_uom_cd_type" minOccurs="0"/>
            <xsd:element name="whpk_qty" type="pos_integer_type"/>
            <xsd:element name="whpk_length_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="whpk_width_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="whpk_height_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="whpk_dim_uom_code" type="dim_uom_code_type" minOccurs="0"/>
            <xsd:element name="whpk_weight_qty" type="weight_qty_type" minOccurs="0"/>
            <xsd:element name="whpk_weight_uom_cd" type="weight_uom_cd_type" minOccurs="0"/>
            <xsd:element name="vnpk_qty" type="pos_integer_type"/>
            <xsd:element name="vnpk_length_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="vnpk_width_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="vnpk_height_qty" type="dim_qty_type" minOccurs="0"/>
            <xsd:element name="vnpk_dim_uom_code" type="dim_uom_code_type" minOccurs="0"/>
            <xsd:element name="vnpk_cube_qty" type="cube_qty_type" minOccurs="0"/>
            <xsd:element name="vnpk_cube_uom_cd" type="cube_uom_cd_type" minOccurs="0"/>
            <xsd:element name="vnpk_weight_qty" type="weight_qty_type" minOccurs="0"/>
            <xsd:element name="vnpk_weight_uom_cd" type="weight_uom_cd_type" minOccurs="0"/>
            <xsd:element name="vnpk_cspk_code" type="cspk_code_type" minOccurs="0"/>
            <xsd:element name="pallet_ti_qty" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="pallet_hi_qty" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="whse_align_type_cd" type="whse_align_type" minOccurs="0"/>
            <xsd:element name="min_whse_life_qty" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="whse_rotation_code" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="crush_factor_code" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="conveyable_ind" type="ind_type_YN"/>
            <xsd:element name="temp_sensitive_ind" type="ind_type_YN"/>
            <xsd:element name="hazmat_id" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="mfgr_sugd_rtl_amt" type="retail_amt_type" minOccurs="0"/>
            <xsd:element name="cust_base_rtl_amt" type="retail_amt_type"/>
            <xsd:element name="base_unit_rtl_amt" type="retail_amt_type"/>
            <xsd:element name="unit_cost_amt" type="unit_cost_amt_type"/>
            <xsd:element name="discount_ind" type="ind_type_YN"/>
            <xsd:element name="proj_yr_sale_qty" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="sell_qty" type="comp_qty_type"/>
            <xsd:element name="sell_uom_code" type="comp_uom_cd_type"/>
            <xsd:element name="price_comp_qty" type="comp_qty_type" minOccurs="0"/>
            <xsd:element name="price_comp_uom_cd" type="comp_uom_cd_type" minOccurs="0"/>
            <xsd:element name="item_status_code" type="item_status_code_type"/>
            <xsd:element name="item_ord_eff_date" type="date_type" minOccurs="0"/>
            <xsd:element name="item_type_code" type="pos_smallint_type"/>
            <xsd:element name="repl_subtype_code" type="pos_smallint_type"/>
            <xsd:element name="item_rplnshbl_ind" type="ind_type_YN"/>
            <xsd:element name="cancel_whn_out_ind" type="ind_type_YN"/>
            <xsd:element name="variable_wt_ind" type="ind_type_YN"/>
            <xsd:element name="backrm_scale_ind" type="ind_type_YN"/>
            <xsd:element name="whse_area_code" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="online_ind" type="ind_type_YN"/>
            <xsd:element name="store_ind" type="ind_type_YN"/>
            <xsd:element name="assortment_type_cd" type="assortment_type_cd_type" minOccurs="0"/>
            <xsd:element name="shlf_life_days_qty" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="replenish_unit_ind" type="ind_type_YN"/>
            <xsd:element name="ideal_temp_lo_qty" type="smallint_type" minOccurs="0"/>
            <xsd:element name="ideal_temp_hi_qty" type="smallint_type" minOccurs="0"/>
            <xsd:element name="accept_temp_lo_qty" type="smallint_type" minOccurs="0"/>
            <xsd:element name="accept_temp_hi_qty" type="smallint_type" minOccurs="0"/>
            <xsd:element name="guar_sales_ind" type="ind_type_YN"/>
            <xsd:element name="vnpk_weight_fmt_cd" type="vnpk_weight_fmt_cd_type" minOccurs="0"/>
            <xsd:element name="prime_xref_item_nbr" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="xref_seq_nbr" type="pos_integer_type" minOccurs="0"/>
            <xsd:element name="origin_country_cd" type="char_2_type" minOccurs="0"/>
            <xsd:element name="marshal_id" type="pos_smallint_type" minOccurs="0"/>
            <xsd:element name="mbm_code" type="mbm_code_type"/>
        </xsd:sequence>
    </xsd:group>
    <!-- Type definitions -->
    <xsd:simpleType name="action_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>
            <xsd:pattern value="[ACD]"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="date_type">
        <xsd:restriction base="xsd:date"/>
    </xsd:simpleType>
    <xsd:simpleType name="smallint_type">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="-32768"/>
            <xsd:maxInclusive value="32767"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="pos_integer_type">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="10"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="pos_smallint_type">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="0"/>
            <xsd:maxInclusive value="32767"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="ind_type_YN">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>
            <xsd:pattern value="[YN]"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="char_2_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="upc_nbr_type">
        <xsd:restriction base="xsd:long">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="15"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="vendor_stock_id_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="20"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="dept_nbr_type">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="1"/>
            <xsd:totalDigits value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="vendor_nbr_type">
        <xsd:restriction base="xsd:int">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="6"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="vendor_dept_nbr_type">
        <xsd:restriction base="xsd:int">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="vendor_seq_nbr_type">
        <xsd:restriction base="xsd:int">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="1"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="item_desc_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="25"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="shelf_label_desc_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="10"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="upc_desc_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="15"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="signing_desc_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="40"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="dim_qty_type">
        <xsd:restriction base="xsd:decimal">
            <xsd:totalDigits value="9"/>
            <xsd:fractionDigits value="3"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="dim_uom_code_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="cube_qty_type">
        <xsd:restriction base="xsd:decimal">
            <xsd:totalDigits value="9"/>
            <xsd:fractionDigits value="3"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="cube_uom_cd_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="weight_qty_type">
        <xsd:restriction base="xsd:decimal">
            <xsd:totalDigits value="11"/>
            <xsd:fractionDigits value="4"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="weight_uom_cd_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="retail_amt_type">
        <xsd:restriction base="xsd:decimal">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="11"/>
            <xsd:fractionDigits value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="unit_cost_amt_type">
        <xsd:restriction base="xsd:decimal">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="13"/>
            <xsd:fractionDigits value="4"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="cspk_code_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>
            <xsd:pattern value="[CBX]"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="whse_align_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="comp_qty_type">
        <xsd:restriction base="xsd:decimal">
            <xsd:minInclusive value="0"/>
            <xsd:totalDigits value="9"/>
            <xsd:fractionDigits value="4"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="comp_uom_cd_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="2"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="item_status_code_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>
            <xsd:pattern value="[AIDX]"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="assortment_type_cd_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>          
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="vnpk_weight_fmt_cd_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>
            <xsd:pattern value="[FVX]"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="mbm_code_type">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="1"/>
            <xsd:pattern value="[HIMP]"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

Upvotes: 0

Views: 62

Answers (1)

Michael Kay
Michael Kay

Reputation: 163587

The error message tells you precisely what is wrong (despite its peculiar capitalisation), and tells you exactly what to do about it. Your schema contains references such as

type="pos_integer_type"

which is a reference to a type having local name pos_integer_type in no namespace. But your schema (on line 129) defines a type with local name pos_integer_type in the target namespace of the schema, which is http://www.sample.com/itemfile (not a good choice of URI, by the way, unless you own the domain www.sample.com). If you want to reference this type, you need type="z:pos_integer_type", with xmlns:z="http://www.sample.com/itemfile" added to the xs:schema element.

Sorry if I'm just restating what's already in the error message, but I don't know how to explain it any other way.

Upvotes: 0

Related Questions