简体   繁体   English

sp_xml_preparedocument 出现错误“在 XML 文档中只允许一个顶级元素”

[英]sp_xml_preparedocument go with error “Only one top level element is allowed in an XML document”

I'am trying to execute sp_xml_preparedocument and geting error "Only one top level element is allowed in an XML document"我正在尝试执行 sp_xml_preparedocument 并收到错误“在 XML 文档中只允许一个顶级元素”

my T-SQL commands:我的 T-SQL 命令:

DECLARE @aa XML
DECLARE @idoc int
SET @aa =(select * from db_name for xml auto, xmldata) 

@aa now is @aa 现在是

<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes" name="Schema7">
<ElementType name="Person" content="empty" model="closed">
  <AttributeType name="preson_id" dt:type="i4" />
  <AttributeType name="Name" dt:type="string" />
  <AttributeType name="Surname" dt:type="string" />
  <AttributeType name="guid" dt:type="uuid" />
  <AttributeType name="version" dt:type="bin.base64" />
  <attribute type="preson_id" />
  <attribute type="Name" />
  <attribute type="Surname" />
  <attribute type="guid" />
  <attribute type="version" />
 </ElementType>
</Schema>
  <Person xmlns="x-schema:#Schema7" preson_id="1" Name="Иван" Surname="Иванов" guid="2E739E87-3CA4-4ED8-ADD0-8B59957668B8" version="AAAAAAAAB9E=" />
  <Person xmlns="x-schema:#Schema7" preson_id="2" Name="Николай" Surname="Николаев" guid="BDC41C59-D70F-4B70-954E-4918B9516AF8" version="AAAAAAAAB9I=" />
  <Person xmlns="x-schema:#Schema7" preson_id="3" Name="Максим" Surname="Максимов" guid="740E57F3-56BA-48B8-92AF-978D7B1D2712" version="AAAAAAAAB9M=" />

EXEC sp_xml_preparedocument @idoc OUTPUT, @aa

The XML parse error 0xc00ce555 occurred on line number 1, near the XML text ""
Msg 6602, Level 16, State 2, Procedure sp_xml_preparedocument, Line 1
The error description is 'Only one top level element is allowed in an XML document

I'am new in this, and i need help))) An one more question - How parse timestamp type?我是新来的,我需要帮助))) 还有一个问题 - 如何解析时间戳类型?

if i use如果我使用

SET @aa =(select * from db_name for xml elements, root('root'), type) 

sp_xml_preparedocument works fine, OPENXML returns all values of my db_table, but timestamp values looks not the same as were.. sp_xml_preparedocument 工作正常,OPENXML 返回我的 db_table 的所有值,但时间戳值看起来与以前不同。

Sorry for my bad English对不起我的英语不好

确保您尝试获取的记录没有重复条目

SELECT @aa returns SELECT @aa 返回

<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes" name="Schema7">
<ElementType name="Person" content="empty" model="closed">
  <AttributeType name="preson_id" dt:type="i4" />
  <AttributeType name="Name" dt:type="string" />
  <AttributeType name="Surname" dt:type="string" />
  <AttributeType name="guid" dt:type="uuid" />
  <AttributeType name="version" dt:type="bin.base64" />
  <attribute type="preson_id" />
  <attribute type="Name" />
  <attribute type="Surname" />
  <attribute type="guid" />
  <attribute type="version" />
 </ElementType>
</Schema>
  <Person xmlns="x-schema:#Schema7" preson_id="1" Name="Иван" Surname="Иванов" guid="2E739E87-3CA4-4ED8-ADD0-8B59957668B8" version="AAAAAAAAB9E=" />
  <Person xmlns="x-schema:#Schema7" preson_id="2" Name="Николай" Surname="Николаев" guid="BDC41C59-D70F-4B70-954E-4918B9516AF8" version="AAAAAAAAB9I=" />
  <Person xmlns="x-schema:#Schema7" preson_id="3" Name="Максим" Surname="Максимов" guid="740E57F3-56BA-48B8-92AF-978D7B1D2712" version="AAAAAAAAB9M=" />

An XML document must have one root element only - see W3C specification .一个 XML 文档必须只有一个根元素——参见W3C 规范

Thus in you case if Schema is the root element you cannot add the Person elements at the end因此,在您的情况下,如果 Schema 是根元素,则您不能在最后添加 Person 元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sp_xml_prepare文档 - sp_xml_preparedocument 为sp_xml_preparedocument配置名称空间 - Configuring namespace for sp_xml_preparedocument 如何修复解析为SQL时XML文档错误中仅允许一个顶级元素 - How to fix Only one top level element is allowed in an XML document error when parsing into SQL 使用sp_xml_preparedocument批量插入父表和子表 - Bulk insert in parent and child table using sp_xml_preparedocument 如何使用包含不带前缀的命名空间的 sp_xml_preparedocument 在 TSQL 中读取 XML? - How do I read XML in TSQL using sp_xml_preparedocument that includes a namespace without prefix? 如何处理&#39;sp_xml_preparedocument&#39;中的无效字符(SQL Server 20188 R2) - How to handle invalid character in 'sp_xml_preparedocument' (SQL Server 20188 R2) sp_xml_preparedocument无法在openquery语句中返回? (无法确定元数据) - sp_xml_preparedocument fails to return in openquery statement? (The metadata could not be determined) 发生错误usind sp_xml_removedocument - Error occured usind sp_xml_removedocument 错误:XML 声明必须是文档中的第一个节点,并且它之前不允许出现空白字符 - Error: XML declaration must be the first node in the document, and no white space characters are allowed to appear before it 存在命名空间时,无法使用Sp_XML_Prepare文档解析XML - Unable to Parse XML using Sp_XML_Prepare document when namespaces are present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM