“将字符集加载到数据集中时,”字段节点内的XPath选择无效。无法找到..“错误

时间:2011-04-20 06:42:34

标签: c# xml xsd dataset

我想将XML模式(Main.xsd)添加到数据集,该数据集包含另一个模式(base.xsd),用于定义前一个模式中使用的复杂类型。

Main.xsd有一个定义xs:unique的块,带有selector和field,用于唯一地将特定元素定义为主键。 这是Main.xsd:

<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema"  xmlns="http://tempuri.org/Main.xsd" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"  targetNamespace="http://tempuri.org/Main.xsd"  attributeFormDefault="unqualified" elementFormDefault="qualified" version="3.0.4 01-07-2011">

<xs:include schemaLocation="base.xsd"/>

<xs:complexType name="Employees">
<xs:sequence>
  <xs:element name="EmployeeID" type="UE_SignedInt"/>
</xs:sequence>
</xs:complexType>

<xs:element name="Report" type=" Employees" />

<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element ref=" Report " />
  </xs:choice>
</xs:complexType>
<xs:unique name="ReportConst" msdata:PrimaryKey="true">
  <xs:selector xpath=".//Report" />
  <xs:field xpath="EmployeeID" />
</xs:unique>
</xs:element> 
</xs:schema>

类型“UE_SignedInt”在base.xsd中定义,它包含在Main.xsd中。

现在,当我尝试将Main.xsd包含到数据集中时,它会抛出一个错误:“字段节点内的无效XPath选择。找不到EmployeeID“因为EmployeeID使用base.xsd中定义的类型。

如果我对此元素使用某些基本类型(如“xs:int”),则加载到数据集中可以正常工作。有谁可以帮我解决这个问题??

2 个答案:

答案 0 :(得分:1)

当我将唯一块修改为:

时,问题得以解决
<xs:unique name="ReportConst" msdata:PrimaryKey="true"> 
<xs:selector xpath="." /> 
<xs:field xpath="EmployeeID" /> 
</xs:unique>

答案 1 :(得分:0)

您需要指定UE_SignedInt元素的名称空间。

    <xs:element name="EmployeeID" type="xxx:UE_SignedInt"/>