属于覆盖命名空间的命名空间会发生什么?
What happens to a namespace which belongs to an overrideen namespace?
命名空间 xmlns 在 "parent" 中定义并在 "child" 中被覆盖。由于我的 xsi 在 "parent" 和 "child" 中相同,我是否还需要覆盖 "child" 中的 xsi 名称空间?
<parent xmlns="namespace_A" xmlns:xsi="namespace_C" xsi:schemaLocation="namespace_D">
<child xmlns="namespace_B" xsi:schemaLocation="namespace_E">
</child>
</parent>
我尝试过的所有在线验证器都验证了 xml 是否已被接受,但在处理 xml 时出现错误,它说 xsi 未绑定在 "child".[=14 中=]
我遇到这个问题的具体代码是:
<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2017-08-24T12:54:26</responseDate>
<request verb="ListRecords" from="2017-08-08" set="J:10.1007:53599" metadataPrefix="CR_UNIXML" resumptionToken="91554975-0bb1-4cf5-86ae-b2222e6fe01f">http://oai.crossref.org/OAIHandler</request>
<!-- recipient 96 crlabs2 -->
<ListRecords>
<record>
<header>
<!-- citation-id: 92292627; type: JOURNAL_ARTICLE; -->
<identifier>info:doi/10.1007/s40278-017-34281-1</identifier>
<datestamp>2017-08-11</datestamp>
<setSpec>J</setSpec>
<setSpec>J:10.1007</setSpec>
<setSpec>J:10.1007:53599</setSpec>
</header>
<!-- org.crossref.xs.xml.XmlSchemaInfo@ae01b520 -->
<metadata>
<crossref xmlns="http://www.crossref.org/xschema/1.1" xsi:schemaLocation="http://www.crossref.org/xschema/1.1 http://www.crossref.org/schema/unixref1.1.xsd">
这是外部服务作为响应给出的 xml。我只想使用接受 xslt 文件以检索所需数据的同一外部服务提供的处理器来处理一些数据,但出现以下错误:
ERROR: 'The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "crossref" is not bound.'
ERROR: 'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "crossref" is not bound.'
错误发生在 class XMLNSDocumentScannerImpl 方法 scanStartElement() 中。在以下循环中,uri 为 null 并抛出错误。
// bind attributes (xmlns are already bound bellow)
int length = fAttributes.getLength();
// fLength = 0; //initialize structure
for (int i = 0; i < length; i++) {
fAttributes.getName(i, fAttributeQName);
String aprefix = fAttributeQName.prefix != null
? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING;
String uri = fNamespaceContext.getURI(aprefix);
// REVISIT: try removing the first "if" and see if it is faster.
//
if (fAttributeQName.uri != null && fAttributeQName.uri == uri) {
// checkDuplicates(fAttributeQName, fAttributes);
continue;
}
if (aprefix != XMLSymbols.EMPTY_STRING) {
fAttributeQName.uri = uri;
if (uri == null) {
fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,
"AttributePrefixUnbound",
new Object[]{fElementQName.rawname,fAttributeQName.rawname,aprefix},
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
fAttributes.setURI(i, uri);
// checkDuplicates(fAttributeQName, fAttributes);
}
}
被覆盖的命名空间没有任何反应。它们不再是相应前缀设计的名称空间或默认名称空间。就这些了。
"overriding" 具有相同命名空间 URI 的相同 xmlns:prefix 没有效果。正如您所注意到的,您的 xmlns:xsi 总是相同的,因为它应该是相同的,它不需要在根元素之外的其他地方定义。
另请注意,尽管允许,但没有必要在根元素以外的其他地方定义 xsi:schemaLocation。您可以在第一个 xsi:schemaLocation 中直接给出所有命名空间的所有模式的完整列表,这样您就可以拥有另一个。
All the online validators I tried verify the xml as accepted but I get
an error when processing the xml, which says xsi is not bound in
"child".
在您给出的示例中,xsi 确实已绑定。声称不是的处理器是错误的。这是错误的,给出了不正确的结果。
但您的真实文档可能与您提供的示例不完全相同。
在上升元素中绑定的前缀不太可能在后代元素中解除绑定,但有可能。因此,需要示例。
命名空间 xmlns 在 "parent" 中定义并在 "child" 中被覆盖。由于我的 xsi 在 "parent" 和 "child" 中相同,我是否还需要覆盖 "child" 中的 xsi 名称空间?
<parent xmlns="namespace_A" xmlns:xsi="namespace_C" xsi:schemaLocation="namespace_D">
<child xmlns="namespace_B" xsi:schemaLocation="namespace_E">
</child>
</parent>
我尝试过的所有在线验证器都验证了 xml 是否已被接受,但在处理 xml 时出现错误,它说 xsi 未绑定在 "child".[=14 中=]
我遇到这个问题的具体代码是:
<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2017-08-24T12:54:26</responseDate>
<request verb="ListRecords" from="2017-08-08" set="J:10.1007:53599" metadataPrefix="CR_UNIXML" resumptionToken="91554975-0bb1-4cf5-86ae-b2222e6fe01f">http://oai.crossref.org/OAIHandler</request>
<!-- recipient 96 crlabs2 -->
<ListRecords>
<record>
<header>
<!-- citation-id: 92292627; type: JOURNAL_ARTICLE; -->
<identifier>info:doi/10.1007/s40278-017-34281-1</identifier>
<datestamp>2017-08-11</datestamp>
<setSpec>J</setSpec>
<setSpec>J:10.1007</setSpec>
<setSpec>J:10.1007:53599</setSpec>
</header>
<!-- org.crossref.xs.xml.XmlSchemaInfo@ae01b520 -->
<metadata>
<crossref xmlns="http://www.crossref.org/xschema/1.1" xsi:schemaLocation="http://www.crossref.org/xschema/1.1 http://www.crossref.org/schema/unixref1.1.xsd">
这是外部服务作为响应给出的 xml。我只想使用接受 xslt 文件以检索所需数据的同一外部服务提供的处理器来处理一些数据,但出现以下错误:
ERROR: 'The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "crossref" is not bound.'
ERROR: 'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "crossref" is not bound.'
错误发生在 class XMLNSDocumentScannerImpl 方法 scanStartElement() 中。在以下循环中,uri 为 null 并抛出错误。
// bind attributes (xmlns are already bound bellow)
int length = fAttributes.getLength();
// fLength = 0; //initialize structure
for (int i = 0; i < length; i++) {
fAttributes.getName(i, fAttributeQName);
String aprefix = fAttributeQName.prefix != null
? fAttributeQName.prefix : XMLSymbols.EMPTY_STRING;
String uri = fNamespaceContext.getURI(aprefix);
// REVISIT: try removing the first "if" and see if it is faster.
//
if (fAttributeQName.uri != null && fAttributeQName.uri == uri) {
// checkDuplicates(fAttributeQName, fAttributes);
continue;
}
if (aprefix != XMLSymbols.EMPTY_STRING) {
fAttributeQName.uri = uri;
if (uri == null) {
fErrorReporter.reportError(XMLMessageFormatter.XMLNS_DOMAIN,
"AttributePrefixUnbound",
new Object[]{fElementQName.rawname,fAttributeQName.rawname,aprefix},
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
fAttributes.setURI(i, uri);
// checkDuplicates(fAttributeQName, fAttributes);
}
}
被覆盖的命名空间没有任何反应。它们不再是相应前缀设计的名称空间或默认名称空间。就这些了。
"overriding" 具有相同命名空间 URI 的相同 xmlns:prefix 没有效果。正如您所注意到的,您的 xmlns:xsi 总是相同的,因为它应该是相同的,它不需要在根元素之外的其他地方定义。
另请注意,尽管允许,但没有必要在根元素以外的其他地方定义 xsi:schemaLocation。您可以在第一个 xsi:schemaLocation 中直接给出所有命名空间的所有模式的完整列表,这样您就可以拥有另一个。
All the online validators I tried verify the xml as accepted but I get an error when processing the xml, which says xsi is not bound in "child".
在您给出的示例中,xsi 确实已绑定。声称不是的处理器是错误的。这是错误的,给出了不正确的结果。
但您的真实文档可能与您提供的示例不完全相同。
在上升元素中绑定的前缀不太可能在后代元素中解除绑定,但有可能。因此,需要示例。