为什么我的 XSD 验证在 Visual Studio Code 中无法正常工作?

huangapple go评论71阅读模式
英文:

Why isn't my XSD validation working in Visual Studio Code?

问题

我正在尝试在Visual Studio Code中使用现有的XSD文件验证我的XML,并尝试了一些Redhat XML中建议的验证过程,但难以获得任何验证结果。

同事成功使用xsi:SchemaLocation进行验证,但对我来说似乎有些问题。 (特定的文件路径和地址已更改)

XML中的标头:

<COSD:COSD
  xmlns="http://www.address.uk/location/location"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.address.uk/location/location file:///c%3a/Users/Username/Documents/Temp/filename.xsd">
  <MAINXML/>
</COSD:COSD>

XSD标头我没有从预定义模式更新,但如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:COSD="http://www.address.uk/location/location" 
  version="9-0-1" #
  id="AnonymisedName" 
  xmlns="http://www.address.uk/location/location" 
  targetNamespace="http://www.address.uk/location/location" 
  finalDefault="extension">
  <MAINBODY>
</xs:schema>

xmlnstargetNamespace 与XML标头中的 xlmns 匹配。

我必须漏掉了一些东西以将XML和XSD绑定在一起以进行验证,但非常感谢任何关于思路/故障排除的建议。

尝试了https://github.com/redhat-developer/vscode-xml/blob/main/docs/Validation.md 中的其他方法。

尝试了上述使用 xsi:SchemaLocation 的方法在其他地方已经可以工作,但在我的情况下似乎有问题,因此使用此方法。

期望在VS Code的问题部分看到模式验证问题。

英文:

I am trying to validate my XML against an existing XSD file in Visual Studio Code and have tried a few of the suggested validation processes in Redhat XML, but struggling to get any of the validation results to appear.

A colleague managed to get the validation to work with xsi:SchemaLocation but something is not working for me. (specific file paths and addresses changed)

Header in XML:

<COSD:COSD
  xmlns="http://www.address.uk/location/location"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.address.uk/location/location file:///c%3a/Users/Username/Documents/Temp/filename.xsd">
  <MAINXML/>
</COSD:COSD>

XSD header I haven't updated from the predefined schema, but it comes as per the below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:COSD="http://www.address.uk/location/location" 
  version="9-0-1" #
  id="AnonymisedName" 
  xmlns="http://www.address.uk/location/location" 
  targetNamespace="http://www.address.uk/location/location" 
  finalDefault="extension">
  <MAINBODY>
</xs:schema>

The xmlns and targetNamespace matches the xlmns in the XML header.

I must be missing something in order to bind the XML and XSD together to get the validation, but any thoughts/troubleshooting ideas would be greatly appreciated.

Tried other methods from https://github.com/redhat-developer/vscode-xml/blob/main/docs/Validation.md.

The one attempted above using xsi:SchemaLocation has been made to work elsewhere but not in my instance, hence using this method.

Expecting to see schema validation issues in VS Code Problems section.

答案1

得分: 1

Solution Found: 问题与Visual Studio Code分配的代码工作区相关。该工作区被分配给Jupyter Workbook,因此需要通过“文件” --> “从文件打开工作区”来删除它。请检查Visual Studio Code的标题是否没有指定不兼容XML的代码工作区,然后xsi:SchemaLocation绑定方法将起作用。

英文:

Solution Found: The issue was relating to the Code Workspace that Visual Studio Code was assigned to. The workspace was assigned to Jupyter Workbook so this needed to be removed via the File --> Open Workspace from File. Check that the Visual Studio Code header does not specify a Code Workspace that is not xml compatible, then the xsi:SchemaLocation binding method will work.

huangapple
  • 本文由 发表于 2023年5月24日 19:23:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定