472,340 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,340 software developers and data experts.

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 1342

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
by: brandon | last post by:
I want to speed up the validation of some of my fairly large and detailed XML files. In particular there is a set of child elements and...
by: Christian Staffe | last post by:
Hi, I would like to check for a partial match between an input string and a regular expression using the Regex class in .NET. By partial match, I...
by: john morales | last post by:
Hi guys, I have a problem and i know there must be a solution for this as it is such a basic common practice in asp.net development. Scenario:...
by: js | last post by:
My form has only one RequiredFieldValidator (called RqValidateSerial) enabled at design time. In the code behind I set the validatior to false...
by: B. Chernick | last post by:
I have an odd problem with validation and I'm not sure if the problem's in ASP, VB, Javascript, or a third-party component. We created a user...
by: bbalet.free.fr | last post by:
The “Add Web Reference” Visual tool generates bad classes (from WSDL schema) for ComplexType containing only one element (wsdl.exe and...
by: Microsoft News Group | last post by:
I am adding some field validation throught column changing with partial classes. I am debugging it and when it hits this.ColumnChanging +=...
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.