Has anyone successfully been able to use an XmlValidatingReader (Framework
1.1) to validate documents against XML Schemas that haven't been added to
the XmlValidatingReader.Schemas collection first?
e.g. I have the following XML document, and I want to validate it.
<doc xmlns="my-first-namspace">
<node/>
<another xmlns="my-second-namespace"/>
</doc>
So I create an XmlValidatingReader and instruct it to use a custom
XmlResolver.
XmlTextReader tr = new XmlTextReader(fullyQualifiedPath);
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.ValidationType = ValidationType.Schema;
vr.XmlResolver = new MyXmlResolver();
vr.ValidationEventHandler += new ValidationEventHandler(ValidationEvent);
I then try to load the document, which causes it to be validated.
XPathDocument doc = new XPathDocument(vr);
At this point, my MyXmlResolver.ResolveUri() is called with
fullyQualifiedPath as the relativeUri parameter, and the System.Uri I return
is then passed to MyXmlResolver.GetEntity(). So far so good.
But the next thing that happens is my ValidationEvent() method gets called
with an XmlSeverityType.Warning message: "Could not find schema information
for the element 'my-first-namespace:doc'. [...]".
I was expecting MyXmlResolver to be used to locate an XML Schema for
my-first-namespace.
If I modify my instance document to provide a schema location hint...
<doc xmlns="my-first-namspace" xsi:schemaLocation="my-first-namespace
mfns.xsd">
<node/>
<another xmlns="my-second-namespace"/>
</doc>
....the MyXmlResolver is called to resolve mfns.xsd.
But I can't rely on the instance document having an xsi:schemaLocation hint,
so is there any other way I can get XmlValidatingReader to ask me where to
get an XML Schema from when it comes across a new namespace?
I can't add the schema to the XmlValidatingReader.Schemas collection because
I don't know which schemas the instance document needs to be validated
against until the instance document is loaded. (I guess I could load the
document twice, once with validation and once without, but I was hoping to
achieve everything in one hit, as it were.)
Thanks,
- Lee 1 1635
Lee Chapman wrote: I was expecting MyXmlResolver to be used to locate an XML Schema for my-first-namespace.
Xmlresolver is supposed to resolve resources by URI, not by namespace,
so no URI - no call to resolver.
But I can't rely on the instance document having an xsi:schemaLocation hint, so is there any other way I can get XmlValidatingReader to ask me where to get an XML Schema from when it comes across a new namespace?
Correct me if I'm wrong, but I believe there is no way of doing so. Also
XmlSchemaCollection class is sealed, so you cannoty extend it with such
behaviour.
I can't add the schema to the XmlValidatingReader.Schemas collection because I don't know which schemas the instance document needs to be validated against until the instance document is loaded. (I guess I could load the document twice, once with validation and once without, but I was hoping to achieve everything in one hit, as it were.)
Well, if you can try to peek into XML document before validating using
XmlTextReader (just open document and read till doument element, figure
out namespace and then close reader).
--
Oleg Tkachenko
XML Insider http://www.tkachenko.com/blog This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: trek |
last post by:
Good evening,
I am trying to locate a standard (commonly accepted) XML schema for
managing documents. What want to know is if someone has already
created an XML schema for describing the...
|
by: tsolbjor |
last post by:
Is there a schema available for ethical codes?
Im thinking of a code of conduct document that should be easy to update and
roll out to different platforms and devices.
I might use some...
|
by: tsolbjor |
last post by:
What program is suitable for making schema instance documents?
I have tried Word, but I feel that there must be some other tools that are
better than that.
--
thomas
|
by: Ian Pilcher |
last post by:
I am using an XML-based format to define my applications data types.
For example, here are the "primitive" types that holds a Java Integers
and Floats:
<type name="int" class="Value">...
|
by: comic_rage |
last post by:
Hi,
I am trying to add an annotation with a documentation, which contains
several nodes. So far, I having a problem on how to code this with C#.
Any help is appreciated.
<xsd:annotation>...
|
by: pradeepsarathy |
last post by:
Hi all,
Does the SAX parser has eventhandlers for parsing xml schema.
Can we parse the xml schema the same way as we parse the xml document
using SAX Parser.
Thanks in advance.
-pradeep
|
by: Lord0 |
last post by:
Hi there,
How do I define in a schema that an element (<element>) may have any
content i.e. text, other elements, partial elements, angle brackets
etc?
So all of the following would be valid:...
|
by: markus.meier |
last post by:
Hi,
I'm searching a tool to generate XML files based on an existing XML
schema file. Does somebody know a free tool that supports this
feature?
Thanks Markus
|
by: --CELKO-- |
last post by:
Is there a simple way to get a COUNT(*) for all tables in a schema in
DB2 LUW 9.0?
|
by: Peter |
last post by:
I'm looking for a freely available tool that can generate xml instance
documents from an xml schema. I'm aware of Sun's xmlgen, but I cannot
find a valid web link to it. Does anyone have a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |