Validating XML using UBL XSD
Hi
I am trying to learn using UBL 2.1 xml specificaton because our company is looking into integrating it with our CRM software. Right now I sampled creating a class out of UBL-Invoice-2.1.xsd and was able to create and open xml document using that class. The problem that I am trying to ask is with regards to validation, I tried to validate the simple xml file I've generated and the sample xml from UBL(UBL-Invoice-2.1-Example) and I keep getting warnings "Could not find schema information for the element 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'".
Here is the sample code I used in C# to validate xml against xsd:
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2", @"path\UBL-Invoice-2.1.xsd");
XmlSchema compiledSchema = null;
//add all imported schemas in Invoice-2.1 xsd
foreach (XmlSchema schema in schemaSet.Schemas())
{
compiledSchema = schema;
}
XmlReaderSettings xmlreadSet = new XmlReaderSettings();
xmlreadSet.Schemas.Add(compiledSchema);
xmlreadSet.ValidationType = ValidationType.Schema;
xmlreadSet.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
xmlreadSet.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
xmlreadSet.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
xmlreadSet.ValidationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
xmlreadSet.ValidationEventHandler += new ValidationEventHandler(XmlValidationEventHandler);
XmlReader xread = XmlReader.Create(openDialog.OpenFile(), xmlreadSet);
while (xread.Read())
I have added all the schemas included in the Invoice-2.1.xsd and I have used the sample xml from UBL(which I think should be complete) but im still getting those warnings. If anyone can point out anything that I am doing wrong that would be great.
Thanks in advance.
Unblock the file?
Hi Andrew,
I am not sure if this is going to be much help but worth trying.
It happened to me once where I got the same warning in Visual Studio.
Right click the icon of the xsd file to the file properties and you will see an 'unblock' button at the bottom, click on it.
Reopen your xml file in visual studio and you should be able to run the xsd validation successfully.
The UBL Dev list is the place to ask
Thank you for this post, Andrew, but you will get better visibility for your question when you subscribe to the UBL Dev mail list. See the top paragraph of http://ubl.xml.org/forum for details.
Personally, I've not used XML with C# ... no doubt someone on UBL Dev would be able to help.
Good luck!
. . . . . Ken