xml - XML 文档的第一行是什么?

所以在我们编写 XML Schema 之前,很多教程都使用这个:

 <?xml version='1.0'?>

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

我的问题是,这部分是做什么用的?该网站具体是什么,我们为什么要使用它?还有其他方法可以做到这一点吗?

如果有帮助,我这样做是为了将 Excel 工作表转换为 XML。

最佳答案

XML声明

<?xml version='1.0'?>是一个 XML declaration并且不是特定于 XSD,而是一般的 XML 文档。

[Definition: XML documents should begin with an XML declaration which specifies the version of XML being used.]

由于 XSD 是一个 XML 文档,它也可能有一个 XML 声明。

这是 XML 声明 ( XMLDecl ) 的 BNF,带有指向其组成部分定义的链接:

XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

注意: Only one XML declaration is permitted in well-formed XML, and it must be at the top if anywhere .如果您违反此要求,您将看到如下错误:

The processing instruction target matching "[xX][mM][lL]" is not allowed.

你必须fix the problem在您的 XML 将是 well-formed 之前.


XML 架构实例命名空间

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"是 namespace特殊申报 XML Schema instance namespace 强>。作为命名空间URI,其目的是为了便于控制组件名称的分组。 An XML namespace URI does not have to be retrievable .

另见

  • What are XML namespaces关于命名空间的目的 一般而言。
  • Schema-Related Markup in Documents Being Validated对于 XSD 属性 使用 xsi特别是。 ( xsi:typexsi:nilxsi:schemaLocationxsi:noNamespaceSchemaLocation )

https://stackoverflow.com/questions/35835870/

相关文章:

haskell - 为我的编译器实现代数数据类型

shell - 自解压 tar 存档(shell 脚本)

api - 在 POST 中将数据安全地发送到 REST API

ruby-on-rails - ApplicationController.rb 中如何使用设计方法

r - 使用SparkR,如何将字符串列拆分为 'n'多列?

intellij-idea - 为什么 IntelliJ 中的 SBT 可以通过 Internet

sql-server - -S 服务器时出现 sqlcmd 错误

Git - 删除或编辑别名

zsh - 复制数组 1 :1 in zsh

c# - 如何处理内存不足异常字符串生成器