4

I am editing an XML file in Visual Studio that references an XSD at a relative path with spaces in one of the folder names. Visual studio does not seem to be impressed.

If I remove the space names from the folder it works and I can navigate.

<?xml version="1.0" encoding="UTF-8"?>
  <SyncTests xmlns="http://www.mimosa.org/ccom4" releaseID="1.0" versionID="4.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.mimosa.org/ccom4 ../../CCOM/BOD/Messages/OperationandCondition/synctests.xsd">

But the original folder name has spaces in "Operation and Condition".

<?xml version="1.0" encoding="UTF-8"?>
  <SyncTests xmlns="http://www.mimosa.org/ccom4" releaseID="1.0" versionID="4.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.mimosa.org/ccom4 ../../CCOM/BOD/Messages/Operation and Condition/synctests.xsd">

I've been trying to get it to work with various incantations of file:/// and %20 for spaces but haven't been able to get it to work yet.

The folder structure is coming from another repo, and I'm hoping to be able to leave it as-is (with spaces).

enter image description here

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Derek
  • 7,615
  • 5
  • 33
  • 58

1 Answers1

3

The value of xsi:schemaLocation is a sequence space-separated pairs of XML namespace values and XSD file locations. Since whitespace is used to delimit both these component pairs and the parts of each pair, clearly unescaped whitespace cannot also appear in the XSD file specification.

The solution is to use %20 instead of raw space characters within the file path to the XSD. You say you've tried this unsuccessfully in various combinations with other experiments. Backtrack to the case you proved to work when you eliminated the spaces in the directory path the XSD. Using that exact case, make only a single change: Substitute %20 where you wish there to be a space, and make the corresponding change to the path in filesystem (using actual, not escaped, spaces there – use no more or less than were used in the xsi:schemaLocation value.

That should work. If it doesn't post a minimum, complete, verifiable example that proves that it does not, along with the XSD processor that you're using. Be sure to actually validate a document instance against the associated XSD to separate significant XML-XSD issues from insignificant Visual Studio IDE parsing limitations.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I've added a screenshot with %20. I am able to get the same document to work if I remove the %20 and the spaces from the folder name in windows explorer. – Derek Mar 22 '21 at 17:00
  • 1
    Define "work": Validate using a conforming XSD processor, or satisfy the Visual Studio IDE such that the green squiggly line disappears? – kjhughes Mar 22 '21 at 17:02
  • Trying to satisfy the Visual Studio IDE. I think I have been able to validate xml files against documents with c# code, even with the spaces in the filename. So I guess it is more of an issue with Visual Studio. – Derek Mar 22 '21 at 17:04
  • NOTE: visual studio is happy with this: xsi:schemaLocation="http://www.mimosa.org/ccom4 ../../CCOM\BOD\Messages\OPERAT~1\SYNCTE~1.XSD"> not ideal... – Derek Mar 22 '21 at 17:05
  • 1
    I recommend that you stick with standards rather than pander to Visual Studio limitations. – kjhughes Mar 22 '21 at 17:11
  • I hit similar problems in vscode. This path works for me with vscode: xsi:schemaLocation="http://www.mimosa.org/ccom4 ../../CCOM/BOD/Messages/OPERAT~1/synctests.xsd"> But no love on the spaces. – Derek Mar 22 '21 at 17:25