我正在尝试根据 XSD 验证 XML。 XML 在根元素中包含命名空间声明:
xmlns="http://www.sample.com/itemfile"
目前在验证时出现错误:
Src-resolve.4.1: 错误解析组件'pos_integer_type'。检测到“pos_integer_type”没有命名空间,但没有目标命名空间的组件无法从架构文档“null”中引用。如果“pos_integer_type”打算有一个命名空间,可能需要提供一个前缀。如果“pos_integer_type”没有命名空间,则应将没有“命名空间”属性的“导入”添加到“null”。
如果我从 XML 文件中删除
xmlns="http://www.sample.com/itemfile"
,它可以与现有的 xsd 一起使用。
我不明白这里到底出了什么问题。请指导我如何修改现有的 xsd 并验证包含命名空间的 XML。
这两个类似的现有问题并没有太大帮助,因为我正在做他们所指的事情:
如何使用 schemaLocation 或 noNamespaceSchemaLocation 将 XML 链接到 XSD?
xmlns、xmlns:xsi、xsi:schemaLocation 和 targetNamespace?
您可以在线验证 XML 文件,网址为 https://www.freeformatter.com/xml-validator-xsd.html
非常感谢您提供的任何帮助。
XML 文档
<?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 文档
<?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>