I have a schema with the following attributes:
<xs:schema id="FooFile"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Foostandards.com"
elementFormDefault="qualified"
xmlns="http://Foostandards.com">
I have an XDocument constructor with the following attributes on the root tag (FooFile).
XDocument Foo2Xml = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Foo2 file specifications implemented in xml"),
new XElement("FooFile",
new XAttribute(XNamespace.Xmlns + "xsi", "http://Foostandards.com"),
new XAttribute(xsi + "schemaLocation", "http://Foostandards.com FooFile.xsd"), etc
I get the following error logged when I run the XDocument Validate method:
"The targetNamespace parameter '' should be the same value as the targetNamespace 'http://Foostandards.com' of the schema."
I have the targetNamespace parameter in the Schema and I can't find info that tells me that it even belongs in the XML document attributes (or how to code it).
I figured it out. The error had nothing to do with the schema or the XDocument parameters. It was the Add method to the SchemaSet object that had a null value for the targetNamespace parameter.
My code:
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("", XmlReader.Create(new StringReader(xsd)));
Where xsd is a string representation of my schema. Note the "" as the first parameter of the Add method.
Code should have been:
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("http://Foostandards.com", XmlReader.Create(new StringReader(xsd)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With