src-resolve: Cannot resolve the name 'ds:Signature' to an 'element declaration' component
Asked Answered
B

5

9

I want to do schema validation using an XSD file. When I import the XSD file to Eclipse, without running the validation class, I have the following error:

src-resolve: Cannot resolve the name 'ds:Signature' to an 'element declaration' component

I am kinda new to XML vs XSD validation process. Although I have looked for similar questions on google, I couldn't figure out what's wrong here.

The XSD file is as follows:

 <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xerces="http://xerces.apache.org"
        xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
        xmlns:abc="http://abc.123.com" targetNamespace="http://abc.123.com"
        xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" elementFormDefault="qualified"
        attributeFormDefault="unqualified">
        <xs:import namespace="http://uri.etsi.org/01903/v1.3.2#" schemaLocation="XAdES.xsd"/>
        <xs:import namespace="http://uri.etsi.org/01903/v1.4.1#" schemaLocation="XAdESv141.xsd"/>
        <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
    <xs:complexType name="headerType">
        <xs:sequence>
            <xs:element name="doorNumber" type="xs:int"/>
            <xs:element ref="ds:Signature"/>
        </xs:sequence>
    </xs:complexType>

How should I modify the XSD to fix this error?

Bronwyn answered 18/6, 2015 at 19:59 Comment(2)
Um... Take the ds: out of the ref, or add a schema for ds as you have xs. (You have to actually read both the error message and the XSD. Three lines up from the bottom.)Consolidate
perhaps that the element Signature does not exist in the schema "xmldsig-core-schema.xsd". notice that xml is case sensitive.Maenad
B
12

If you have xmldsig-core-schema.xsd in the same directory as your XSD, and if it is the same as this XSD, then you should not be getting an error about a failure to resolve ds:Signature.

Therefore, I suspect that your import is failing, and you're missing or ignoring a warning such as the following:

[Warning] try.xsd:9:56: schema_reference.4: Failed to read schema document 'xmldsig-core-schema.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

Try this XSD as a test; it loads directly from the URL for xmldsig-core-schema.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
           xmlns:abc="http://abc.123.com"
           targetNamespace="http://abc.123.com"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">
  <xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
             schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
  <xs:complexType name="headerType">
    <xs:sequence>
      <xs:element name="doorNumber" type="xs:int"/>
      <xs:element ref="ds:Signature"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

I've tested the above XSD and found that it eliminates the resolution error that you were seeing.

Battle answered 18/6, 2015 at 23:29 Comment(1)
updating signature schema location with the URL seems to work.I don't have the error anymore.thank you so much!Bronwyn
T
3

As an alternative you can cache locally the xmldsig-core-schema.xsd, put it in the same directory of your xsd schema, an then let your original

    <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>

This will resolve your problem of importing a file from W3C website and save time of execution.

Translation answered 28/6, 2017 at 13:48 Comment(0)
C
0

I just generated XSD files from cXML DTD files using Visual Studio 2019 and ran into the same problem.

In my case solution contained multiple steps:

  1. Save digital signature schema file xmldsig-core-schema.xsd (downloadable from https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd) in the same folder as you cXML schema files
  2. Search for & replace all the occurrences of xmlns:ds="uri:ds" with xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  3. Find & delete all the occurances of <xs:import namespace="uri:ds" />

After these steps cXML schema files validated and I was able to generate C# classes using command:

xsd /c cXML.xsd xmldsig-core-schema.xsd

Note: xsd tool requires both schemas to be passed in.

Countryandwestern answered 21/7, 2020 at 12:2 Comment(0)
M
0

I updated the .xsd file by modifying the line:

    <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#"
    schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
Miltiades answered 4/8, 2021 at 17:53 Comment(0)
S
0

I have the same problem and in order not to open another thread, I will contribute with more information. I need to validate an XDocument against a schema that has schemas linked to it.

This is my validation code:

XmlSchemaSet schema = new();
schema.Add("http://www.sii.cl/SiiDte", "EnvioDTE_v10.xsd");
xDocument.Validate(schema, ValidationEventHandler!);
XDocument doc = XDocument.Parse(xmlsetdte);
doc.Validate(
schema,
   (o, e) =>
  {
       Console.WriteLine("{0}", e.Message);
  }
     );
  doc.Validate(schema, ValidationEventHandler!);

This is the main xsd: main xsd

The second xsd:

second xsd

and third:

third xsd

all the xsd files are in the app path, i have also tried to change "schemaLocation" as suggested in this thread: post but nothing has worked for me.

Which xsd should I modify? This is the error code: exception

Sung answered 15/2, 2023 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.