xml 元素或属性与 QName 生成不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4852622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:32:35  来源:igfitidea点击:

Element or attribute do not match QName production

xmlsoapxsdxml-validationogc

提问by capdragon

I have a schema that i have "flattened" using XML Editor. After i flatten it i get a validation error. What can i do to fix it?

我有一个使用 XML 编辑器“扁平化”的模式。在我展平它后,我收到一个验证错误。我能做些什么来解决它?

Error Message:

错误信息:

F [Xerces] Element or attribute do not match QName production: QName::=(NCName':')?NCName.

F [Xerces] 元素或属性不匹配 QName 产生:QName::=(NCName':')?NCName。

code:

代码:

<xs:import namespace="http://www.opengis.net/gml"
    schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"
    xmlns:="http://www.opengis.net/gml/3.1.1" />
<xs:annotation xmlns:="http://www.opengis.net/sps/1.0">
    <xs:documentation>
        <copyright>                 SPS is an OGC Standard.                 Copyright (c)
            2007,2010 Open Geospatial Consortium, Inc. All Rights Reserved.                 To
            obtain additional rights of use, visit http://www.opengeospatial.org/legal/ .
        </copyright>
    </xs:documentation>
</xs:annotation>

Here's a screenshot that might better illustrate my error: enter image description here

这是一个屏幕截图,可以更好地说明我的错误: 在此处输入图片说明

EDIT:

编辑:

Remove the colon somehow. What exactly does this "flattening" supposed to do?

以某种方式去除冒号。这种“扁平化”究竟应该做什么?

The flattening of the xsd takes an xsdwith a lot of includes and puts it all into one file (without any includes).

xsd 的扁平化需要一个包含大量包含的xsd,并将其全部放入一个文件中(没有任何包含)。

回答by jasso

xmlns:=is invalid syntax. The colon is extra or the namespace prefix after the colon is missing. Correct syntax would be xmlns="http://some.uri"or xmlns:something="http://some.uri"

xmlns:=是无效的语法。冒号是多余的或冒号后的命名空间前缀丢失。正确的语法是xmlns="http://some.uri"xmlns:something="http://some.uri"

Note that you have 2un-needed colons: first one on line 1002 (where the red arrow is pointing) and the second one is on the line 1003. This gives a hint that there might be even more of them.

请注意,您有2个不需要的冒号:第一个在第 1002 行(红色箭头指向的地方),第二个在第 1003 行。这暗示可能还有更多冒号。

"QName" refers to "qualified name" and "NCName" refers to "non-colonized name". Non-colonized name is an XML name that doesn't contain a colon character (:). Qualified name is either a non-colonized name or combination of two non-colonized names separated with a colon. For example "abc:defgh". The part before the colon is called the namespace prefix and the part after the colon is called the local name. If a qualified name has a namespace prefix, then that prefix mustbe bound to a namespace-URI with a prefixed namespace declaration, for example xmlns:abc="http://some.uri".

“QName”是指“合格名称”,“NCName”是指“非殖民化名称”。非殖民化名称是不包含冒号字符 (:) 的 XML 名称。限定名称是非殖民化名称或以冒号分隔的两个非殖民化名称的组合。例如“abc:defgh”。冒号前的部分称为命名空间前缀,冒号后的部分称为本地名称。如果限定名称具有命名空间前缀,则该前缀必须绑定到具有前缀命名空间声明的命名空间 URI,例如xmlns:abc="http://some.uri"

回答by Daniel Cotter

In case it's helpful to anyone else, I got the same error message and realized that what was causing it was the colon in the namespace URI, i.e. "http://whatever". I had been concatenating the namespace URI to the resources and properties directly rather than registering the namespace as a symbol, so a resource or a property might look like "http://hl7.org/fhir/:Observation", which of course has two colons and therefore does not follow the "QName::=(NCName':')?NCName" production format.

如果它对其他人有帮助,我收到了相同的错误消息,并意识到导致它的原因是命名空间 URI 中的冒号,即“ http://whatever”。我一直将命名空间 URI 直接连接到资源和属性,而不是将命名空间注册为符号,因此资源或属性可能看起来像“ http://hl7.org/fhir/:Observation”,这当然有两个冒号,因此不遵循“QName::=(NCName':')?NCName”生产格式。

I fixed it by first registering the namespace with the model:

我通过首先向模型注册命名空间来修复它:

model.setNsPrefix("fhir","http://hl7.org/fhir/");

and then prepending the namespace in my resources and properties:

然后在我的资源和属性中添加命名空间:

Resource root = model.getResource("fhir:Patient");
root.addProperty(model.createProperty("fhir:Patient.identifier"), patient.identifier);