469,645 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Problem with partial validation

I have a problem when I select node elements from an xml file and validata
each node againts the schema. I use XmlValidatingReader and it complains
about elements not being declared.

I have defined a schema for details of a particular service request. Below
is a schema similar to the one that I defined:

<?xml version="1.0" standalone="yes" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.mycompany.com" xmlns:dsc="http://www.mycompany.com"
<xs:element name="Requests">
<xs:choice maxOccurs="unbounded">
<xs:element name="Request">
<xs:element name="Input1" type="xs:unsignedLong" minOccurs="1"
maxOccurs="1" />
<xs:element name="Input2" type="xs:unsignedLong" minOccurs="1"
maxOccurs="1" />
<xs:element name="Response" minOccurs="0" maxOccurs="1">
<xs:element name="Result" type="xs:boolean" />
<xs:element name="Message" type="xs:string" />
<xs:element name="DateTime" type="xs:dateTime" />

A simple Xml file that conforms to the above schema would have batched
requests and look like

<?xml version="1.0"?>
<tst:Requests xmlns:tst="http://www.mycompany.com">

I have a program that validates and processes this XML file. What I would
like to do is that if the xml file is valid but some of the request elements
do not conform to my schema, I would still process the ones that are valid
(against my schema). So what I do is:

1) Load the Xml file and select the request nodes. This step would make sure
that the xml file is well formed (valid). Below is the snippet and it works

XmlTextReader rdr = new XmlTextReader(xmlFile);
System.Xml.XmlDocument doc = new XmlDocument();
//Create a namespace manager
System.Xml.XmlNamespaceManager nsMngr = new
System.Xml.XmlNodeList rqstLst =
foreach(XmlNode nd in rqstLst)
if( ValidateRequestXml(nd.OuterXml))

2) In ValidateRequestXml, I try to validate just the part of the Xml file
(request element). If it is ok, I can process it. Otherwise, I go to the
next request. This way, a request that does not conform to my schema will
not prevent the processing of valid requests. This is what I do:
NameTable nt = new NameTable();
XmlNamespaceManager nsMngr = new XmlNamespaceManager(nt);
System.Xml.XmlParserContext rqstCtx = new
XmlValidatingReader vRdr = new
XmlValidatingReader(xmlRequest,XmlNodeType.Element ,rqstCtx); //xmlRequest is
nd.OuterXml from step 1
vRdr.ValidationEventHandler +=new
ValidationEventHandler(vRdr_ValidationEventHandler );
Requests ds = new Requests(); //Dataset generated from the schema. I
just read each request into it

xmlRequest is the OuterXml of the selected node elements passed to
ValidateRequestXml and includes a namespace definition. For examples, it
would look like:

<tst:Request xmlns:tst="http://www.mycompany.com">

However, the validating reader seems to have a problem with the inclusion of
the definition of the namespace in the node element. It raises validation
events when I call ds.ReadXml(vRdr) saying that

'http://www.mycompany.com:Request" element not is not declared.
'http://www.mycompany.com:Input1" element not is not declared.
'http://www.mycompany.com:Input2" element not is not declared.

Is the definition of namespace in the selected node causing the validation
to look for the declaration of the elements in a subnamespace?

If I remove the namespace definition from the selected node, the validation
seems to be working ok. Could someone give me an explaination and possibly a
solution or an alternative way of doing partial (element-only) schema

Your responses and time are deeply appreciated.

Jan 11 '06 #1
0 1223

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Lionel B | last post: by
9 posts views Thread by brandon | last post: by
2 posts views Thread by Christian Staffe | last post: by
3 posts views Thread by john morales | last post: by
reply views Thread by js | last post: by
2 posts views Thread by B. Chernick | last post: by
reply views Thread by bbalet.free.fr | last post: by
reply views Thread by Microsoft News Group | last post: by
2 posts views Thread by swethak | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.