diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java
index bde1008ed..8aa791189 100644
--- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java
+++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMDocument.java
@@ -249,10 +249,9 @@ private synchronized void initializeReferencedSchema() {
}
}
if (schemaInstancePrefix != null) {
+ // DOM document can declared xsi:noNamespaceSchemaLocation and xsi:schemaLocation both even it's not valid
noNamespaceSchemaLocation = createNoNamespaceSchemaLocation(documentElement, schemaInstancePrefix);
- if (noNamespaceSchemaLocation == null) {
- schemaLocation = createSchemaLocation(documentElement, schemaInstancePrefix);
- }
+ schemaLocation = createSchemaLocation(documentElement, schemaInstancePrefix);
}
}
}
@@ -862,4 +861,4 @@ else if (noNamespaceSchemaLocation != null) {
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java
index 6ff6e3543..328b60aca 100644
--- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java
+++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java
@@ -124,13 +124,14 @@ public static void computeCompletionResponses(ICompletionRequest request,
}
if(inRootElement) {
- if(!schemaLocationExists && !noNamespaceSchemaLocationExists) {
+ if(!schemaLocationExists) {
//The xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes can be used in a document
//to provide hints as to the physical location of schema documents which may be used for ·assessment·.
documentation = SCHEMA_LOCATION_DOC;
name = actualPrefix + ":schemaLocation";
createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings);
-
+ }
+ if(!noNamespaceSchemaLocationExists) {
documentation = NO_NAMESPACE_SCHEMA_LOCATION_DOC;
name = actualPrefix + ":noNamespaceSchemaLocation";
createCompletionItem(name, isSnippetsSupported, generateValue, editRange, null, null, documentation, response, settings);
diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMDocumentTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMDocumentTest.java
index a72db6f2d..dc3ee32f6 100644
--- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMDocumentTest.java
+++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMDocumentTest.java
@@ -263,4 +263,18 @@ public void testUsesSchemaTrueAbsolutePath() {
Assert.assertTrue(d.hasSchemaInstancePrefix());
Assert.assertTrue(d.usesSchema("/home/nikolas/nested/testXSD.xsd")); //bad path
}
+
+ @Test
+ public void testNoNamespaceSchemaLocationAndShemaLocationBoth() {
+ String text = "" + //
+ " ";
+ TextDocument textDocument = new TextDocument(text, "/home/test.xml");
+ DOMDocument d = DOMParser.getInstance().parse(text, textDocument.getUri(), null);
+ Assert.assertNotNull(d.getNoNamespaceSchemaLocation());
+ Assert.assertNotNull(d.getSchemaLocation());
+ }
}
diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java
index 54df624fe..d4ca57841 100644
--- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java
+++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java
@@ -21,7 +21,6 @@
import org.eclipse.lsp4xml.XMLAssert;
import org.eclipse.lsp4xml.commons.BadLocationException;
import org.eclipse.lsp4xml.services.XMLLanguageService;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -345,7 +344,7 @@ public void completionWithXMLSchemaContentChanged() throws Exception {
+ " \r\n"
+ " \r\n" + " \r\n" + "";
Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes());
- XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 4, false,
+ XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 5, false,
c("variant", "variant=\"\""));
// Update resources.xsd, Schema doesn't define variant attribute -> no
@@ -366,7 +365,7 @@ public void completionWithXMLSchemaContentChanged() throws Exception {
// + " \r\n"
+ " \r\n" + " \r\n" + "";
Files.write(Paths.get("target/xsd/resources.xsd"), schema.getBytes());
- XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 3, false);
+ XMLAssert.testCompletionFor(xmlLanguageService, xml, null, null, "target/resources.xml", 4, false);
}
@@ -448,7 +447,7 @@ public void xsiCompletionNotUsingXSIName() throws BadLocationException {
" \r\n" +
"";
- XMLAssert.testCompletionFor(xml, 3, c("XXY:nil", "XXY:nil=\"true\""), c("XXY:type", "XXY:type=\"\""));
+ XMLAssert.testCompletionFor(xml, 4, c("XXY:nil", "XXY:nil=\"true\""), c("XXY:type", "XXY:type=\"\""), c("XXY:noNamespaceSchemaLocation", "XXY:noNamespaceSchemaLocation=\"\""));
}
@Test
@@ -485,7 +484,7 @@ public void xsiCompletionSchemaLocationExists() throws BadLocationException {
" \r\n" +
"";
- XMLAssert.testCompletionFor(xml, 3, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""));
+ XMLAssert.testCompletionFor(xml, 4, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""), c("xsi:noNamespaceSchemaLocation", "xsi:noNamespaceSchemaLocation=\"\""));
}
@Test
@@ -498,7 +497,7 @@ public void xsiCompletionNoNamespaceSchemaLocationExists() throws BadLocationExc
" \r\n" +
"";
- XMLAssert.testCompletionFor(xml, 2, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""));
+ XMLAssert.testCompletionFor(xml, 3, c("xsi:nil", "xsi:nil=\"true\""), c("xsi:type", "xsi:type=\"\""), c("xsi:schemaLocation", "xsi:schemaLocation=\"\""));
}
private void testCompletionFor(String xml, CompletionItem... expectedItems) throws BadLocationException {
diff --git a/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/main.xml b/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/main.xml
new file mode 100644
index 000000000..60ea5c73f
--- /dev/null
+++ b/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/main.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/xsd2Namespace.xsd b/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/xsd2Namespace.xsd
new file mode 100644
index 000000000..712c2abf7
--- /dev/null
+++ b/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/xsd2Namespace.xsd
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/xsdNoNamespace.xsd b/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/xsdNoNamespace.xsd
new file mode 100644
index 000000000..0bbbc5477
--- /dev/null
+++ b/org.eclipse.lsp4xml/src/test/resources/xsd/differentNamespace/xsdNoNamespace.xsd
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file