The namespace xmlns is defined in "parent" and is overridden in "child". Since my xsi is the same in "parent" and "child" do I also need to override the xsi namespace in "child"?
<parent xmlns="namespace_A" xmlns:xsi="namespace_C" xsi:schemaLocation="namespace_D">
<child xmlns="namespace_B" xsi:schemaLocation="namespace_E">
</child>
</parent>
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".
The particular code where I have this problem is:
<?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">
This is the xml given as response by an external service. I just want to process some of the data with a processor given by the same external service which accepts xslt files to retrieve the desired data but I get the following error:
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.'
The error occurs in the class XMLNSDocumentScannerImpl, method scanStartElement(). In the following loop the uri is null and the error is thrown.
// 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);
}
}
Nothing happens to namespaces that are overridden. They just aren't anymore the namespace designed by the corresponding prefix or as default. That is all.
There is no effect in "overriding" the same xmlns:prefix with the same namespace URI. As you have noted that your xmlns:xsi is always the same, as it should, it needs not be defined elsewhere than in the root element.
Also note that it is not necessary, though allowed, to define xsi:schemaLocation elsewhere than in the root element. You can give directly the complete list of all the schemas for all the namespaces in the first xsi:schemaLocation, thus sparing you to have another.
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".
In the example you've given, xsi is bound indeed. A processor that claims it is not, is wrong. It's buggy, giving incorrect results.
But maybe your real documents aren't exactly as you gave an example.
It's unlikely, but possible, that a prefix that was bound in an ascendant element, would be unbound in a descendant element. So, examples needed.