Hello to all --
I am familiar with Xml in general and NET 1.1 Xml, but I am new to the
..NET 2.0 changes in System.Xml.
I am trying to validate an XML document that is based on a schema that
imports several other schemas.
I am using VS2005 and .NET 2.0 on Windows 2003 Server with SP1.
I am using the Validate method of the XmlDocument class. I am passing in
an instance of XmlReader.
My code is as follows (I'll explain the commented code in a second):
XmlDocument xd = new XmlDocument();
XmlReaderSettin gs readerSettings = new XmlReaderSettin gs();
//XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlUrlResolver resolver = new XmlUrlResolver( );
//schemaSet.Add(" http://co.marin.ca.us/ComplaintReques tDocument/1.0",
"I10\\Complaint Request.xsd");
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2",
"I10\\jxdm\\3.0 .2\\jxdm.xsd");
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2/proxy/ncic_2000/1.0.1",
"I10\\jxdm\\3.0 .2\\proxy\\ncic _2000\\1.0.1\\n cic_2000.xsd");
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2/proxy/usps_states/1.0",
"I10\\jxdm\\3.0 .2\\proxy\\usps _states\\1.0\\u sps_states.xsd" );
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2/proxy/xsd/1.0",
"I10\\jxdm\\3.0 .2\\proxy\\xsd\ \1.0\\xsd.xsd") ;
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/ncic_2000/1.0.1",
"I10\\jxdm\\nci c_2000\\1.0.1\\ ncic_2000.xsd") ;
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/usps_states/1.0",
"I10\\jxdm\\usp s_states\\1.0\\ usps_states.xsd ");
//readerSettings. Schemas = schemaSet;
readerSettings. ValidationType = ValidationType. Schema;
readerSettings. ValidationFlags |=
(XmlSchemaValid ationFlags.Proc essSchemaLocati on);
readerSettings. CloseInput = true;
readerSettings. IgnoreComments = true;
System.Net.Netw orkCredential creds = new
System.Net.Netw orkCredential(" Administrator", <<PWD>>", "<<LOCAL MACHINE
NAME>>");
resolver.Creden tials = creds;
readerSettings. XmlResolver = resolver;
XmlReader xr = XmlReader.Creat e(new
StringReader(xm lDoc.DocumentEl ement.OuterXml) , readerSettings,
parserContext);
xd.Load(xr);
ValidationEvent Handler eventHandler = new
ValidationEvent Handler(Validat ionEventHandler );
xd.Validate(eve ntHandler);
As soon as I hit the last line during debugging, I get the follow
exception:
System.InvalidO perationExcepti on was unhandled
Message="The XmlSchemaSet on the document is either null or has no schemas
in it. Provide schema information before calling Validate."
Source="System. Xml"
StackTrace:
at System.Xml.XmlD ocument.Validat e(ValidationEve ntHandler
validationEvent Handler, XmlNode nodeToValidate)
at System.Xml.XmlD ocument.Validat e(ValidationEve ntHandler
validationEvent Handler)
at BizTalkAlternat ives.InsertComp ReqXmlTest.Main (String[] args) in
C:\Documents and Settings\dlutz\ My Documents\Visua l Studio
2005\Projects\B izTalkAlternati ves\InsertCompR eqXmlTest\Inser tCompReqXmlTest .cs:line
60
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence
assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
From what I have been able to read about System.Xml in .NET 2.0, I
expected the validator to resolve the schemaLocation attributes (which use
relative paths) and use them to validate the document. However, that is not
what happens. What I am missing here?
Finally, if I uncomment the code lines above where I add the schemas to
the XmlSchemaSet, all works fine and my test documents are validated as
expected.
Thanks for suffering through this rather lengthy post. Any help here
would be appreciated.
David Lutz
Sr. Prog./Analyst
County of Marin (California) 1 5140
When you load the XmlDocument using a validating reader, at load time we set
the Schemas property of the XmlDocument to be the same as that of the
XmlReaderSettin gs object with which the validating reader was created. That
is why you commented code does not throw an exception.
But when you do not load the XmlReaderSettin gs object with the schemas, then
the validating reader will create its local schema set from schema locations
parsed in the xml (if the XmlSchemaValida tionFlags.Proce ssSchemaLocatio n is
set, as it is in your example) and use this for validation.
Since this schema set is not set back onto the reader settings object (as
you might be creating multiple readers using the same reader settings), the
xml document does not have access to the schemas that the reader loaded.
Hope that explains the behavior below. For XmlDocument.Val idate(),
ProcessSchemaLo cation, ProcessInlineSc hema flags are turned off by default
and there is currently no public way to set them.
Thanks,
Priya
"dlutz" <dl***@nospam.e mailwrote in message
news:ur******** ******@TK2MSFTN GP06.phx.gbl...
Hello to all --
I am familiar with Xml in general and NET 1.1 Xml, but I am new to the
.NET 2.0 changes in System.Xml.
I am trying to validate an XML document that is based on a schema that
imports several other schemas.
I am using VS2005 and .NET 2.0 on Windows 2003 Server with SP1.
I am using the Validate method of the XmlDocument class. I am passing
in an instance of XmlReader.
My code is as follows (I'll explain the commented code in a second):
XmlDocument xd = new XmlDocument();
XmlReaderSettin gs readerSettings = new XmlReaderSettin gs();
//XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlUrlResolver resolver = new XmlUrlResolver( );
//schemaSet.Add(" http://co.marin.ca.us/ComplaintReques tDocument/1.0",
"I10\\Complaint Request.xsd");
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2",
"I10\\jxdm\\3.0 .2\\jxdm.xsd");
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2/proxy/ncic_2000/1.0.1",
"I10\\jxdm\\3.0 .2\\proxy\\ncic _2000\\1.0.1\\n cic_2000.xsd");
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2/proxy/usps_states/1.0",
"I10\\jxdm\\3.0 .2\\proxy\\usps _states\\1.0\\u sps_states.xsd" );
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/3.0.2/proxy/xsd/1.0",
"I10\\jxdm\\3.0 .2\\proxy\\xsd\ \1.0\\xsd.xsd") ;
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/ncic_2000/1.0.1",
"I10\\jxdm\\nci c_2000\\1.0.1\\ ncic_2000.xsd") ;
//schemaSet.Add(" http://www.it.ojp.gov/jxdm/usps_states/1.0",
"I10\\jxdm\\usp s_states\\1.0\\ usps_states.xsd ");
//readerSettings. Schemas = schemaSet;
readerSettings. ValidationType = ValidationType. Schema;
readerSettings. ValidationFlags |=
(XmlSchemaValid ationFlags.Proc essSchemaLocati on);
readerSettings. CloseInput = true;
readerSettings. IgnoreComments = true;
System.Net.Netw orkCredential creds = new
System.Net.Netw orkCredential(" Administrator", <<PWD>>", "<<LOCAL MACHINE
NAME>>");
resolver.Creden tials = creds;
readerSettings. XmlResolver = resolver;
XmlReader xr = XmlReader.Creat e(new
StringReader(xm lDoc.DocumentEl ement.OuterXml) , readerSettings,
parserContext);
xd.Load(xr);
ValidationEvent Handler eventHandler = new
ValidationEvent Handler(Validat ionEventHandler );
xd.Validate(eve ntHandler);
As soon as I hit the last line during debugging, I get the follow
exception:
System.InvalidO perationExcepti on was unhandled
Message="The XmlSchemaSet on the document is either null or has no
schemas in it. Provide schema information before calling Validate."
Source="System. Xml"
StackTrace:
at System.Xml.XmlD ocument.Validat e(ValidationEve ntHandler
validationEvent Handler, XmlNode nodeToValidate)
at System.Xml.XmlD ocument.Validat e(ValidationEve ntHandler
validationEvent Handler)
at BizTalkAlternat ives.InsertComp ReqXmlTest.Main (String[] args) in
C:\Documents and Settings\dlutz\ My Documents\Visua l Studio
2005\Projects\B izTalkAlternati ves\InsertCompR eqXmlTest\Inser tCompReqXmlTest .cs:line
60
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence
assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
From what I have been able to read about System.Xml in .NET 2.0, I
expected the validator to resolve the schemaLocation attributes (which use
relative paths) and use them to validate the document. However, that is
not what happens. What I am missing here?
Finally, if I uncomment the code lines above where I add the schemas to
the XmlSchemaSet, all works fine and my test documents are validated as
expected.
Thanks for suffering through this rather lengthy post. Any help here
would be appreciated.
David Lutz
Sr. Prog./Analyst
County of Marin (California) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
Suppose I create dynamic web pages with 3 functions (which call other
functions to make everything happen, but these 3 you might think of as
being the top layer):
registerSessions();
sendHtmlToBrowsers();
incrementPageViews();
Is there any chance that incrementPageViews() will be executed? Or, to
|
by: me |
last post by:
I have a Class Library that contains a Form and several helper classes. A
thread gets created that performs processing of data behind the scenes and
the Form never gets displayed (it is for debug puposes only and is not
normally visable to the user.) The Thread function is actually in the Form
class.
Now.. What I am seeing is that when I create an instance of this Class
Library's Form, which starts the worker thread, it seems to hose up...
|
by: Martin Marcher |
last post by:
Hi,
I've read several questions and often the answer was
'C knows nothing about .'
So if C knows that little as some people say, what are the benefits, I
mean do other languages know more or is it a benefit that C knows nearly
nothing (what I can think about is that C is the largest common divisor
defined on most available platforms)?
|
by: Suyog_Linux |
last post by:
I wish to know how the free()function knows how much memory to be
freed as we only give pointer to allocated memory as an argument to
free(). Does system use an internal variable to store allocated memory
when we use malloc().
Plz help......
|
by: Maersa |
last post by:
hi all,
what does the following mean ?
class A
{
public string @return;
}
also, once an object is casted to class "A" how do i recast it to a "string"
| |
by: Anoop |
last post by:
Hi,
I am new to this newsgroup and need help in the following questions.
1. I am workin' on a GUI application. Does C# provides Layout Managers the
way Java does to design GUI? I know that it can be done using the designer
but I intentionally don't want to use that. The one reason is that you
cannot change the code generated by the designer. The other could be that
you have more free hand and control to design your GUI.
2....
|
by: Cuthbert |
last post by:
After compiling the source code with gcc v.4.1.1, I got a warning
message:
"/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the
'gets' function is dangerous and should not be used."
Could anybody tell me why gets() function is dangerous??
Thank you very much.
Cuthbert
|
by: Jon Slaughter |
last post by:
When I used to program in windows(back in the days of win95/98) the help
system was very good. You could find out all th details of just about
anything with usually decent explinations of what does what. Now I can't see
to find any time of descriptions that actually describe what means what. Am
I just looking in the wrong place.
For example,
I made a statusStrip control for use in my application. I put in a text box
and a progress bar...
|
by: LJB |
last post by:
If I read a text file from disk into a stream how can I tell if it might
already be valid XML? I'm writing an app to compare two XML files one of
which may need conversion to XML first. My app will do the conversion when
necessary. I plan to call XMLdiffView, from
http://msdn2.microsoft.com/en-us/library/aa302295.aspx, to generate the
differences report.
thanks
LJB
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |