XML Signature element is not declared

前端 未结 2 1743
-上瘾入骨i
-上瘾入骨i 2021-01-12 07:47

I created XSD using Visual StudioXML Tools. And I use following C# code to validate XML and facing this error.

Error

The elem

2条回答
  •  春和景丽
    2021-01-12 08:10

    You are very close. In your XSD, simply replace,

    
    

    with

    
    

    and your XSD will no longer have that error, and your XML will be valid against your XSD.

    Explanation

    XSDs can be composed via xs:import and xs:include. In both cases, the location of the referenced XSD has to be specified with a required schemaLocation attribute, which was missing in OP's original XSD. By adding xs:import/@schemaLocation as shown above, the error is eliminated.


    Update #1:

    When you switched to use a local XSD, you made a mistake in your xs:import:

    Change

     
    

    to

     
    

    (You were following an example for @xsi:schemaLocation in XML documents which has namespace-location pairs; xs:import/@schemaLocation is different.)


    Update #2:

    So my question is how to fix it because in edit mode XML is valid 100%?

    Perhaps this is the disconnect. Editing an XML file in Visual Studio does not automatically validate it against an XSD. You need to do that in code or via a validating XML editor such Oxygen XML Editor or XML Spy.

    Also, your C# validation code may have issues. See Validating an XML against referenced XSD in C#

提交回复
热议问题