473,583 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 XmlValidatingRe ader 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"
targetNamespace ="http://www.mycompany.c om"
xmlns="http://www.mycompany.c om" xmlns:dsc="http ://www.mycompany.c om"
xmlns:msprop="u rn:schemas-microsoft-com:xml-msprop"
elementFormDefa ult="qualified" >
<xs:element name="Requests" >
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="Request">
<xs:complexType >
<xs:sequence>
<xs:element name="Input1" type="xs:unsign edLong" minOccurs="1"
maxOccurs="1" />
<xs:element name="Input2" type="xs:unsign edLong" minOccurs="1"
maxOccurs="1" />
<xs:element name="Response" minOccurs="0" maxOccurs="1">
<xs:complexType >
<xs:sequence>
<xs:element name="Result" type="xs:boolea n" />
<xs:element name="Message" type="xs:string " />
<xs:element name="DateTime" type="xs:dateTi me" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

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.c om">
<tst:Request>
<tst:Input1>1 </tst:Input1>
<tst:Input2>2 </tst:Input2>
</tst:Request>
<tst:Request>
<tst:Input1>3 </tst:Input1>
<tst:Input2>4 </tst:Input2>
</tst:Request>
</tst:Requests>

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
fine.

XmlTextReader rdr = new XmlTextReader(x mlFile);
System.Xml.XmlD ocument doc = new XmlDocument();
doc.Load(rdr);
//Create a namespace manager
System.Xml.XmlN amespaceManager nsMngr = new
XmlNamespaceMan ager(doc.NameTa ble);
nsMngr.AddNames pace("tst","htt p://www.mycompany.c om");
//
System.Xml.XmlN odeList rqstLst =
doc.SelectNodes ("tst:Reques ts/tst:Request",ns Mngr);
//
foreach(XmlNode nd in rqstLst)
{
if( ValidateRequest Xml(nd.OuterXml ))
{
ProcessRequest( nd.OuterXml);
}
}

2) In ValidateRequest Xml, 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();
XmlNamespaceMan ager nsMngr = new XmlNamespaceMan ager(nt);
nsMngr.AddNames pace("txt","htt p://www.mycompany.c om");
System.Xml.XmlP arserContext rqstCtx = new
XmlParserContex t(null,nsMngr,n ull,XmlSpace.No ne);
XmlValidatingRe ader vRdr = new
XmlValidatingRe ader(xmlRequest ,XmlNodeType.El ement,rqstCtx); //xmlRequest is
nd.OuterXml from step 1
vRdr.Schemas.Ad d("http://www.mycompany.c om",xmlSchema );
vRdr.Validation EventHandler +=new
ValidationEvent Handler(vRdr_Va lidationEventHa ndler);
Requests ds = new Requests(); //Dataset generated from the schema. I
just read each request into it
ds.ReadXml(vRdr );

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

<tst:Request xmlns:tst="http ://www.mycompany.c om">
<tst:Input1>1 </tst:Input1>
<tst:Input2>2 </tst:Input2>
</tst:Request>

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.c om:Request" element not is not declared.
'http://www.mycompany.c om:Input1" element not is not declared.
'http://www.mycompany.c om: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
validations?

Your responses and time are deeply appreciated.

Matt
Jan 11 '06 #1
0 1408

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

Similar topics

7
2121
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
9
4433
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 attributes that does not to be validated after it has completed a certain point in the system, but that will still be present in the file. At points later in the system, when these files are read in, I do...
2
7912
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 mean that the input string could not yet be complete but I want to know if a match is possible so far. For instance I want to design a text box to enter a date and validate the correctness of...
3
2823
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: i have many webforms in a site, most with two different custom controls, one is a login module, the other is a generic data entry module. When there are no validation controls on the page there is...
0
882
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 when the form is submitted by certain button click. On the same IIS6 server, I use port :801 as my development site, and :80 as the production site. Both sites has identical configuration. The...
2
1186
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 control (ASP1.1) that encapsulates a third party control (a Telerik RadComboBox). It's really just a Yes/No option box. However due to the Look & Feel of our application, the powers-that-be have...
0
1227
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 wseWsdl3.exe tools have the same problem) : if a ComplexType A contains only one element, the tool don’t generate a class for the ComplexType A. It generates a class only for the element type (B) included...
0
1187
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 += ValidateColumn; It never goes to the method void ValidateColumn(object sender, DataColumnChangeEventArgs e)
2
3003
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 worked in that .htm file. I used the same code in my local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
0
7811
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7922
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8185
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1416
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.