Reputation: 13645
I am referring to the code below for my XML validation from XSD and from a functional point of view it seems to be working fine.
var schemas = new XmlSchemaSet();
schemas.Add("http://microsoft.com/HealthCare/HL7/2X", xsdFilePath);
Boolean result = true;
xdocXml.Validate(schemas, (sender, e) =>
{
result = false;
});
Now, as you can see I had to specify the schema name explicitly even though this information is self contained in XSD itself. Is there any way to extract that information from the XSD so that I do not have to specifically specify that?
Upvotes: 1
Views: 1819
Reputation: 161801
Simply specify null
for the namespace:
var schemas = new XmlSchemaSet();
schemas.Add(null, xsdFilePath);
From XmlSchemaSet.Add Method (String, String):
targetNamespace
Type: System.String
The schematargetNamespace
property, or null to use thetargetNamespace
specified in the schema.
Upvotes: 5