Java, Xerces 2.9.1
insertHere.setAttributeNS(XMLConstants.XML_NS_URI, "xml:space", "preserve");
и
insertHere.setAttributeNS(XMLConstants.XML_NS_URI, "space", "preserve")
оба заканчиваются с атрибутом просто space='preserve'
, без префикса XML.
insertHere.setAttribute( "xml:space", "preserve")
работает, но кажется как-то не так.Я что-то пропустил?
РЕДАКТИРОВАТЬ
Я проверил.
Я прочитал шаблон документа с включенным setNamespaceAware.
Затем я использую следующее, чтобы сделать его копию, и затем я начинаю вставлять новые элементы.
public static Document copyDocument(Document input) {
DocumentType oldDocType = input.getDoctype();
DocumentType newDocType = null;
Document newDoc;
String oldNamespaceUri = input.getDocumentElement().getNamespaceURI();
if (oldDocType != null) {
// cloning doctypes is 'implementation dependent'
String oldDocTypeName = oldDocType.getName();
newDocType = input.getImplementation().createDocumentType(oldDocTypeName,
oldDocType.getPublicId(),
oldDocType.getSystemId());
newDoc = input.getImplementation().createDocument(oldNamespaceUri, oldDocTypeName,
newDocType);
} else {
newDoc = input.getImplementation().createDocument(oldNamespaceUri,
input.getDocumentElement().getNodeName(),
null);
}
Element newDocElement = (Element)newDoc.importNode(input.getDocumentElement(), true);
newDoc.replaceChild(newDocElement, newDoc.getDocumentElement());
return newDoc;
}