Hello,
Below I give more details, but basically the problem I have is that I have XML data that I want to validate against an XML Schema definition (XSD).
The XSD specifies an attribute which has to match a pattern defined by this regular expression:
<xsd:pattern value="((\w:) \w(=\w) ){1,}">
Valid values matching this pattern could be, for instance, something like this:
"ns1:Inwatera_1m=A, ns2:CoastL_1M=B"
However, .NET 2.0 does not seem to agree, since when I validate an XML document containing the value "ns1:Inwatera_1m=A" for an attribute that has to match this pattern I get the following validation error:
"The 'typeName' attribute is invalid - The value 'ns1:Inwatera_1m=A' is invalid according to its datatype ' http://www.hide-link.com/ :TypeNameListType' - The Pattern constraint failed."
I've tried changing the value and it seems that it only accepts single words without ":" or "=" characters.
So, my questions are:
- Why is it .NET 2.0 not matching the value "ns1:Inwatera_1m=A" to the pattern "((\w:) \w(=\w) ){1,}" Is it a bug or it's something I'm doing wrong
- Do you know how .NET 2.0 matches values to patterns when validating XML contents against XSD
Any help/suggestion will be very much appreciated.
Now the details: The C# source code I use, the XML data to test that I use and the XSD:
The code I use to validate my XML contents against the XSD file is the following one (C# on .NET 2.0):
private bool ValidateWFSQuery(string toValidateData)
{
bool isValid = true;
// toValidateData contains the XML data to validate.
// I insert it to a memory stream because XmlReader.Create requires a stream as parameter,
MemoryStream toValidateDataStream = new MemoryStream(UTF8Encoding.Default.GetBytes(toValidateData));
System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = false;
// The XML Schema file I use is wfs.xsd, downloaded from http://www.hide-link.com/
string schemaFilePath = Server.MapPath("~/wfs/SCHEMAS_OPENGIS_NET/wfs/1.1.0/wfs.xsd");
settings.Schemas.Add(null, schemaFilePath);
settings.ValidationType = System.Xml.ValidationType.Schema;
settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(
ValidationCallback);
// If validation errors occur, the method ValidationCallback will be called
try
{
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(toValidateDataStream, settings);
while (reader.Read()) ; // Here is where the validation of the XML file takes place
}
catch (System.Xml.XmlException e)
{
string errorMsg = "Error: XML Format error in file: " + e.Message;
System.Console.WriteLine(errorMsg);
isValid = false;
}
return isValid;
}
This code is based on an example of how to validate XML files against XSD schemas that I found googling around and not using the deprecated XmlValidatingReader.
The XSD document I use (wfs.xsd) is the XML schema document for the OpenGIS Web Feature Service (WFS), v 1.1.0, which can be downloaded from http://www.hide-link.com/ .
The XML data that I am using to test is the following one:
<wfs:GetFeature service="WFS" version="1.1.0"
outputFormat="GML2"
xmlns:topp=" http://www.hide-link.com/ "
xmlns:wfs=" http://www.hide-link.com/ "
xmlns:ogc=" http://www.hide-link.com/ "
xmlns:gml=" http://www.hide-link.com/ "
xmlns:xsi=" http://www.hide-link.com/ "
xsi:schemaLocation=" http://www.hide-link.com/
http://www.hide-link.com/ ">
<!-- HERE I GET THE VALIDATION ERROR!!!! -->
<wfs:Query typeName="ns1:Inwatera_1m=A">
<ogc:Filter>
<ogc:BBOX>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<gml:Envelope srsName=" http://www.hide-link.com/ #4326">
<gml:lowerCorner>-73.99312376470733 40.76203427979042</gml:lowerCorner>
<gml:upperCorner>-73.9239210030026 40.80129519821393</gml:upperCorner>
</gml:Envelope>
</ogc:BBOX>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
Thanks in advance for your help.
David