Basic XmlValidationStep question

Feb 15, 2012 at 9:30 PM

Just getting started with BizUnit 4.0. How do I create an XmlValidationStep without having to specify a schema. The .CHM states that this is possible, yet I receive an error when trying to do this. Works with specifying the schema, but the Vendor provided schema is filled with obsolete contraints. I just want do validations via XPath against the XML instance values. Below is the error received when not providing a SchemaDefinition to the XmlValidationStep

BizUnit.ValidationStepExecutionException: Failed to validate document instance ---> System.InvalidOperationException: The XmlSchemaSet on the document is either null or has no schemas in it. Provide schema information before calling Validate.
This code works, I would just like to remove the schema references.
            var xmlValidationStep = new XmlValidationStep();
            var schemaDefinition = new SchemaDefinition()
                XmlSchemaPath = @"..\..\..\..\MA_Interfaces\MA_Interfaces\CBO_PO_WMi_POASN_2009.xsd",
                XmlSchemaNameSpace = string.Empty

            var xpathProductId = new XPathDefinition
                Description = "Source",
                XPath = "/*[local-name()='tXML' and namespace-uri()='']/*[local-name()='Header' and namespace-uri()='']/*[local-name()='Source' and namespace-uri()='']",
                Value = "HOST"
May 17, 2013 at 1:16 PM
I would also be interested to know if this is possible without modifying the BizUnit source code. It is often the case that third party cannot provide a schema but only an example file from which the schema is generated. This kind of schema is usually not very useful for validation, because schema generator cannot get the minOccurs, maxOccurs attributes right, for example.
May 17, 2013 at 1:42 PM
After checking the source code I don't think this is possible. ValidateXmlInstance is always called and it looks like this:

private XmlDocument ValidateXmlInstance(Stream data, Context context)
    var settings = new XmlReaderSettings();
    foreach (var xmlSchema in _xmlSchemas)
        settings.Schemas.Add(xmlSchema.XmlSchemaNameSpace, xmlSchema.XmlSchemaPath);
    settings.ValidationType = ValidationType.Schema;

    XmlReader reader = XmlReader.Create(data, settings);
    var document = new XmlDocument();

    var eventHandler = new ValidationEventHandler(ValidationEventHandler);


    return document;
As you can see, document.Validate is called even if no schemas were added to the validation step. If I understood correctly, the only way to go is to modify the source code.
Jan 3, 2014 at 6:44 PM
Revisiting this issue now that some time has passed. I still need to do this. I came up with a work-around that I am not thrilled with, but works for me. I created a generic schema, Generic.xsd. It doesn't have anything more than a root element and an <Any> element and I "validate" against that. Allows me to proceed with xpath validations against a 3rd party schema mapping where the 3rd party provided schema has errors and inconsistencies, but I am unable to force a change. Oh well. Hope this helps someone else.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="" xmlns:xs="">
  <xs:element name="tXML">
        <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax" />