// Modify attributes to fix the base URI (spec 4.5.5).
// We only do it to top level included elements, which have a different
// base URI than their include parent.
if (!sameBaseURISourceAsParent()) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
// this causes errors with schema validation, since the schema doesn't specify that these elements can have an xml:base attribute
// TODO: add a user option to turn this off?
// TODO: [base URI] is still an open issue with the working group.
// They're deciding if xml:base should be added if the [base URI] is different in terms
// of resolving relative references, or if it should be added if they are different at all.
// Revisit this after a final decision has been made.
// TODO: Output a relative URI instead of an absolute one.
int index =
attributes.addAttribute(
XML_BASE_QNAME,
XMLSymbols.fCDATASymbol,
fDocLocation.getBaseSystemId());
attributes.setSpecified(index, true);
}
// Modify attributes of included items to do namespace-fixup. (spec 4.5.4)
Enumeration inscopeNS = fNamespaceContext.getAllPrefixes();
while (inscopeNS.hasMoreElements()) {
String prefix = (String)inscopeNS.nextElement();
String parentURI =
fNamespaceContext.getURIFromIncludeParent(prefix);
String uri = fNamespaceContext.getURI(prefix);
if (parentURI != uri && attributes != null) {
if (prefix == XMLSymbols.EMPTY_STRING) {
if (attributes
.getValue(
NamespaceContext.XMLNS_URI,
XMLSymbols.PREFIX_XMLNS)
== null) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
QName ns = (QName)NEW_NS_ATTR_QNAME.clone();
ns.localpart = XMLSymbols.PREFIX_XMLNS;
ns.rawname = XMLSymbols.PREFIX_XMLNS;
attributes.addAttribute(
ns,
XMLSymbols.fCDATASymbol,
uri);
}
}
else if (
attributes.getValue(NamespaceContext.XMLNS_URI, prefix)
== null) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
QName ns = (QName)NEW_NS_ATTR_QNAME.clone();
ns.localpart = prefix;
ns.rawname += prefix;