C
C#5mo ago
Denis

Validating XML files in CSPROJ

I have multiple XML files as project items. These files are filled by developers and are consumed on build by a source generator. A dev can make a typo in the XML and the generator will fail. Yes, it is possible to introduce XML validation into the generator and outout diagnostics that specify the location of the error. But, is it possible to do static XML validation via some XSD while it being edited from Visual Studio/Rider without relying on the generator diagnostics? So that the dev has instant feedback on what they are doing wrong, before they even compile.
6 Replies
Angius
Angius5mo ago
XML schema?
Denis
Denis5mo ago
Elaborate? XSD is my XML schema
Angius
Angius5mo ago
Right right, I missed that. I'd think any competent IDE would provide instant feedback based on XSD
Denis
Denis5mo ago
Yes... But how do I specify the XSD for each XML file? Especially when the XSD is in one project and the XML s are in others. I cannot create references to the project with the xsd
Angius
Angius5mo ago
xsi:schemaLocation https://stackoverflow.com/a/3966381/6042255 You could try using a relative path, I guess But putting that schema file somewhere online — if possible — would probably be the easiest
Denis
Denis5mo ago
I didn't think of that... Great idea, thanks!