推断限制Inference Limitations

根据每个文档中的 XML 元素,从 XML 推断 DataSet 架构的过程会产生不同的架构。The process of inferring a DataSet schema from XML can result in different schemas depending on the XML elements in each document. 例如,考虑以下 XML 文档。For example, consider the following XML documents.

Document1:Document1:

<DocumentElement>  
  <Element1>Text1</Element1>  
  <Element1>Text2</Element1>  
</DocumentElement>  

Document2:Document2:

<DocumentElement>  
  <Element1>Text1</Element1>  
</DocumentElement>  

对于 "Document1",推理过程将生成一个名为 "DocumentElement" 的 数据集 和一个名为 "Element1" 的表,因为 "Element1" 是重复元素。For "Document1," the inference process produces a DataSet named "DocumentElement" and a table named "Element1," because "Element1" is a repeating element.

数据集: DocumentElementDataSet: DocumentElement

表: Element1Table: Element1

Element1_TextElement1_Text
Text1Text1
Text2Text2

但是,对于 "Document2",推理过程将生成一个名为 "NewDataSet" 的 数据集 和一个名为 "DocumentElement" 的表。However, for "Document2," the inference process produces a DataSet named "NewDataSet" and a table named "DocumentElement." 由于“Element1”不具有属性和子元素,它将被推断为列。"Element1" is inferred as a column because it has no attributes and no child elements.

数据集: NewDataSetDataSet: NewDataSet

表: DocumentElementTable: DocumentElement

Element1Element1
Text1Text1

这两个 XML 文档可能本应生成相同的架构,但根据每个文档中包含的不同元素,推断过程生成了极不相同的结果。These two XML documents may have been intended to produce the same schema, but the inference process produces very different results based on the elements contained in each document.

若要避免在从 XML 文档生成架构时可能出现的差异,建议使用 XML 架构定义语言( (XSD) 或 XML 数据在从 XML 加载 数据集 时减少 (XDR) )显式指定架构。To avoid the discrepancies that can occur when generating schema from an XML document, we recommend that you explicitly specify a schema using XML Schema definition language (XSD) or XML-Data Reduced (XDR) when loading a DataSet from XML. 有关使用 XML 架构显式指定 数据集 架构的详细信息,请参阅 从 Xml 架构派生数据集关系结构 (XSD) For more information about explicitly specifying a DataSet schema with XML Schema, see Deriving DataSet Relational Structure from XML Schema (XSD).

请参阅See also