Can I specify a local file location in the Uri parameter for XmlSchemaSet.Add() method?

StackOverflow https://stackoverflow.com/questions/22942480

  •  29-06-2023
  •  | 
  •  

質問

XmlSchemaSet.Add() method takes a Uri and target namespace, but when I try to pass in a local file location it produces an error.

_schemaUri = @"L:\schemaDoc.xsd";
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(_schemaUri, _targetNamespace);

ERROR:

NotSupportedException was caught

The URI prefix is not recognized.
役に立ちましたか?

解決

Yes. You have confused the parameters of the Add method. The first parameter is the target namespace, with the second being the URI. So your code should look like this:

_schemaUri = @"L:\schemaDoc.xsd";
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(_targetNamespace, _schemaUri);

Refer to the documentation for more details:

http://msdn.microsoft.com/en-us/library/1hh8b082%28v=vs.110%29.aspx

他のヒント

According to the MSDN documentation, you have the schemaUri and targetNamespace parameters in the reverse order.

From MSDN:
XmlSchemaSet.Add Method (String, String) Adds the XML Schema definition language (XSD) schema at the URL specified to the XmlSchemaSet.

Namespace:  System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

public XmlSchema Add(
    string targetNamespace,
    string schemaUri
)

Parameters

targetNamespace
Type: System.String
The schema targetNamespace property, or null to use the targetNamespace specified in the schema.

schemaUri
Type: System.String
The URL that specifies the schema to load.  

http://msdn.microsoft.com/en-us/library/1hh8b082(v=vs.110).aspx

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top